1

アプリを初めて実行したときにのみ、このエラーが発生します。なんで?どんな手掛かり?これが私のコードです:

メソッドでユーザーのFacebookの名前と写真を取得していますinit().toogleボタンが有効になっているときにサービスを開始します

public void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "[ACTIVITY] onCreate");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mUserPic = (ImageView) findViewById(R.id.user_pic);
    mText = (TextView) findViewById(R.id.welcome_text);
    mStepValueView = (TextView) findViewById(R.id.step_value);

    // restore facebook session if exist
    SessionStore.restore(facebook, this);

    // Init facebook session
    init();

    // inizialize pedometer
    mStepValue = 0;
    mPaceValue = 0;

    // set map
    mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);
    mapView.setEnabled(true);
    mapController = mapView.getController(); // get MapController
    mapController.setZoom(MAP_ZOOM); // zoom in the map

    // register listener for toggleButton
    ToggleButton toggleButton = (ToggleButton) findViewById(R.id.ToggleButton);
    toggleButton.setOnCheckedChangeListener(toggleButtonListener);

}

public void onResume() {
    Log.i(TAG, "[ACTIVITY] onResume");
    super.onResume();
    if (!facebook.isSessionValid()) {
        mText.setText("User offline");
        mUserPic.setImageBitmap(null);
    } else {
        facebook.extendAccessTokenIfNeeded(this, null);
    }

    // resume pedometer
    mSettings = PreferenceManager.getDefaultSharedPreferences(this);
    mPedometerSettings = new PedometerSettings(mSettings);

    // Read from preferences if the service was running on the last onPause
    mIsRunning = mPedometerSettings.isServiceRunning();

    if (mIsRunning) {
        bindStepService();
    }

    mPedometerSettings.clearServiceRunning();

}

@Override
protected void onPause() {
    Log.i(TAG, "[ACTIVITY] onPause");
    // if (mIsRunning) {
    // unbindStepService();
    // }
    if (mQuitting) {
        mPedometerSettings.saveServiceRunningWithNullTimestamp(mIsRunning);
    } else {
        mPedometerSettings.saveServiceRunningWithTimestamp(mIsRunning);
    }

    super.onPause();
}

ログキャット

06-27 11:48:54.101: E/AndroidRuntime(20313): FATAL EXCEPTION: main
06-27 11:48:54.101: E/AndroidRuntime(20313): java.lang.RuntimeException: Unable to resume activity {it.univpm.dii.socialfoot/it.univpm.dii.socialfoot.SocialFootActivity}: java.lang.NullPointerException
06-27 11:48:54.101: E/AndroidRuntime(20313):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2455)
06-27 11:48:54.101: E/AndroidRuntime(20313):    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2483)
06-27 11:48:54.101: E/AndroidRuntime(20313):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1176)
06-27 11:48:54.101: E/AndroidRuntime(20313):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-27 11:48:54.101: E/AndroidRuntime(20313):    at android.os.Looper.loop(Looper.java:137)
06-27 11:48:54.101: E/AndroidRuntime(20313):    at android.app.ActivityThread.main(ActivityThread.java:4437)
06-27 11:48:54.101: E/AndroidRuntime(20313):    at java.lang.reflect.Method.invokeNative(Native Method)
06-27 11:48:54.101: E/AndroidRuntime(20313):    at java.lang.reflect.Method.invoke(Method.java:511)
06-27 11:48:54.101: E/AndroidRuntime(20313):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-27 11:48:54.101: E/AndroidRuntime(20313):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-27 11:48:54.101: E/AndroidRuntime(20313):    at dalvik.system.NativeStart.main(Native Method)
06-27 11:48:54.101: E/AndroidRuntime(20313): Caused by: java.lang.NullPointerException
06-27 11:48:54.101: E/AndroidRuntime(20313):    at com.google.android.maps.MapActivity.onResume(MapActivity.java:451)
06-27 11:48:54.101: E/AndroidRuntime(20313):    at it.univpm.dii.socialfoot.SocialFootActivity.onResume(SocialFootActivity.java:296)
06-27 11:48:54.101: E/AndroidRuntime(20313):    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1154)
06-27 11:48:54.101: E/AndroidRuntime(20313):    at android.app.Activity.performResume(Activity.java:4545)
06-27 11:48:54.101: E/AndroidRuntime(20313):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2445)
06-27 11:48:54.101: E/AndroidRuntime(20313):    ... 10 more
4

1 に答える 1

0

Facebookがnullになる可能性があるように見えます......これを試してください

public void onResume() {
    Log.i(TAG, "[ACTIVITY] onResume");
    super.onResume();
   if(null!=facebook){ ///<------------
    if (!facebook.isSessionValid()) {
        mText.setText("User offline");
        mUserPic.setImageBitmap(null);
    } else {
        facebook.extendAccessTokenIfNeeded(this, null);
    }
}
于 2012-06-27T10:19:17.210 に答える