5
我的android webview函數onPageFinished
被調用兩次。我不知道爲什麼,但它在android 2.2上運行良好,但是當我將其升級到4+時,它不起作用。代碼附加以下android webview函數onPagefinished被調用兩次
代碼
@Override
public void onPageFinished(WebView view, String url) {
if (url.startsWith(MobileConstants.PUSHPIN_CALLBACK_URL)) {
if (url.indexOf("code=")!=-1) {
String code = url.substring(url.indexOf("code=")+5);
Log.i ("code", code);
if (code != null && !code.equals("") ){
view.setVisibility(View.GONE);
Token accessToken = service.getAccessToken(null, new Verifier(code));
Log.i("access_token",accessToken.getToken());
SharedPreferences settings = getSharedPreferences("access_token" , 0);
SharedPreferences.Editor editor = settings.edit();
if(accessToken.getToken() != null)
editor.putString("access_token", accessToken.getToken());
Intent map3 = new Intent(OAuthAccessTokenActivity.this, Dashboard.class);
map3.putExtra("access_token", accessToken.getToken());
startActivity(map3);
}
} else if (url.indexOf("error=")!=-1) {
view.setVisibility(View.INVISIBLE);
}
}
System.out.println("onPageFinished : " + url);
}
登錄
07-22 14:29:50.523: E/AndroidRuntime(1186): FATAL EXCEPTION: main
07-22 14:29:50.523: E/AndroidRuntime(1186): java.lang.NullPointerException
07-22 14:29:50.523: E/AndroidRuntime(1186): at com.facebook.android.OAuthAccessTokenActivity$1.onPageFinished(OAuthAccessTokenActivity.java:83)
07-22 14:29:50.523: E/AndroidRuntime(1186): at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:327)
07-22 14:29:50.523: E/AndroidRuntime(1186): at android.os.Handler.dispatchMessage(Handler.java:99)
07-22 14:29:50.523: E/AndroidRuntime(1186): at android.os.Looper.loop(Looper.java:137)
07-22 14:29:50.523: E/AndroidRuntime(1186): at android.app.ActivityThread.main(ActivityThread.java:4745)
07-22 14:29:50.523: E/AndroidRuntime(1186): at java.lang.reflect.Method.invokeNative(Native Method)
07-22 14:29:50.523: E/AndroidRuntime(1186): at java.lang.reflect.Method.invoke(Method.java:511)
07-22 14:29:50.523: E/AndroidRuntime(1186): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-22 14:29:50.523: E/AndroidRuntime(1186): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-22 14:29:50.523: E/AndroidRuntime(1186): at dalvik.system.NativeStart.main(Native Method)
哪一個是第83行,這使空指針流行? – charlypu 2012-07-22 15:10:18
令牌accessToken = service.getAccessToken(null,new Verifier(code));問題是一次我得到的代碼,但後得到的代碼之後,事情就OK了我得到訪問令牌,但然後它再次調用此功能,在這個時候代碼已過期,它給出空指針異常 – Muneeb 2012-07-22 15:16:46
我已經解決了這個問題任何人都可以告訴我如何回答它? – Muneeb 2012-07-24 00:15:09