0

FacebookのAndroidチュートリアルからログアウトコードをコピーしました。ログアウトしようとするたびに、nullポインタ例外が発生します。

これがコードです...

private AsyncFacebookRunner mAsyncRunner;

..。

              mAsyncRunner.logout(home.this, new RequestListener() {
              @Override
              public void onComplete(String response, Object state) 
              {
                 /* mPrefs.edit().putBoolean("firstTime", true).commit();
                  userName.setText("Logged out!");*/
              }

              @Override
              public void onIOException(IOException e, Object state) {
                  Log.d("IOExcenption", e.toString());
              }

              @Override
              public void onFileNotFoundException(FileNotFoundException e,
                    Object state) {
                  Log.d("FileNotFoundException", e.toString());
              }

              @Override
              public void onMalformedURLException(MalformedURLException e,
                    Object state) {
                  Log.d("MalformedUrlExpection", e.toString());
              }

              @Override
              public void onFacebookError(FacebookError e, Object state) {
                  Log.d("FacebookError", e.toString());
              }
            });

ログ

 04-29 23:41:35.523: E/AndroidRuntime(1011): java.lang.NullPointerException
 04-29 23:41:35.523: E/AndroidRuntime(1011):    at rageup.android.home.onClick(home.java:177)
 04-29 23:41:35.523: E/AndroidRuntime(1011):    at android.view.View.performClick(View.java:2364)
 04-29 23:41:35.523: E/AndroidRuntime(1011):    at android.view.View.onTouchEvent(View.java:4179)
 04-29 23:41:35.523: E/AndroidRuntime(1011):    at android.widget.TextView.onTouchEvent(TextView.java:6541)
 04-29 23:41:35.523: E/AndroidRuntime(1011):    at android.view.View.dispatchTouchEvent(View.java:3709)
 04-29 23:41:35.523: E/AndroidRuntime(1011):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
 04-29 23:41:35.523: E/AndroidRuntime(1011):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
 04-29 23:41:35.523: E/AndroidRuntime(1011):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
 04-29 23:41:35.523: E/AndroidRuntime(1011):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
 04-29 23:41:35.523: E/AndroidRuntime(1011):    at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
 04-29 23:41:35.523: E/AndroidRuntime(1011):    at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
 04-29 23:41:35.523: E/AndroidRuntime(1011):    at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
 04-29 23:41:35.523: E/AndroidRuntime(1011):    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
 04-29 23:41:35.523: E/AndroidRuntime(1011):    at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
 04-29 23:41:35.523: E/AndroidRuntime(1011):    at android.os.Handler.dispatchMessage(Handler.java:99)
 04-29 23:41:35.523: E/AndroidRuntime(1011):    at android.os.Looper.loop(Looper.java:123)
 04-29 23:41:35.523: E/AndroidRuntime(1011):    at android.app.ActivityThread.main(ActivityThread.java:4363)
 04-29 23:41:35.523: E/AndroidRuntime(1011):    at java.lang.reflect.Method.invokeNative(Native Method)
 04-29 23:41:35.523: E/AndroidRuntime(1011):    at java.lang.reflect.Method.invoke(Method.java:521)
 04-29 23:41:35.523: E/AndroidRuntime(1011):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
 04-29 23:41:35.523: E/AndroidRuntime(1011):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
 04-29 23:41:35.523: E/AndroidRuntime(1011):    at dalvik.system.NativeStart.main(Native Method)
 04-29 23:41:35.534: I/dalvikvm(1011): threadid=7: reacting to signal 3
 04-29 23:41:35.534: E/dalvikvm(1011): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
 04-29 23:41:37.283: I/Process(1011): Sending signal. PID: 1011 SIG: 9

なぜこれが起こっているのかについての提案はありますか?Null Pointer例外は、コードの2番目のブロックの最初の行を参照しています。

4

3 に答える 3

1

あなたのmAsyncRunnerようですnull

初期化はしましたか?

次のように初期化します。

mAsyncRunner = new AsyncFacebookRunner(mFacebook);  //mFacebook is your facebook object.
于 2012-04-30T07:10:16.810 に答える
0

以下のコードを試してください。

public void logout(final Context context,
                   final RequestListener listener,
                   final Object state) {
    new Thread() {
        @Override public void run() {
            try {
                String response = fb.logout(context);
                if (response.length() == 0 || response.equals("false")){
                    listener.onFacebookError(new FacebookError(
                            "auth.expireSession failed"), state);
                    return;
                }
                listener.onComplete(response, state);
            } catch (FileNotFoundException e) {
                listener.onFileNotFoundException(e, state);
            } catch (MalformedURLException e) {
                listener.onMalformedURLException(e, state);
            } catch (IOException e) {
                listener.onIOException(e, state);
            }
        }
    }.start();
}

public void logout(final Context context, final RequestListener listener) {
    logout(context, listener, /* state */ null);
}
于 2012-04-30T07:06:52.410 に答える
0

context が null かどうかを確認し、使用してみてください

 facebook.logout(this);
于 2012-04-30T07:18:08.090 に答える