1

I've been seeing this NullPointerException pop up for my users in my crash trackers. I have not been able to reproduce it myself, and the most mystifying part of it for me is that the exception itself seems to occur in the Android Activity class--at a line, at which, from looking at the Android source, there is no code at all.

Here is the stack trace:

java.lang.RuntimeException: Unable to resume activity {com.catherineapp.android/com.catherineapp.android.HomeAct}: java.lang.NullPointerException
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2448)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2476)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1990)
at android.app.ActivityThread.access$600(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1151)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4477)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.app.Activity.onResume(Activity.java:1212)
at com.catherineapp.android.CABaseAct.onResume(CABaseAct.java:69)
at com.catherineapp.android.HomeAct.onResume(HomeAct.java:468)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1156)
at android.app.Activity.performResume(Activity.java:4775)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2438)   
... 12 more
java.lang.NullPointerException
at android.app.Activity.onResume(Activity.java:1212)
at com.catherineapp.android.CABaseAct.onResume(CABaseAct.java:69)
at com.catherineapp.android.HomeAct.onResume(HomeAct.java:468)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1156)
at android.app.Activity.performResume(Activity.java:4775)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2438)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2476)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1990)
at android.app.ActivityThread.access$600(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1151)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4477)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)

The code at line com.catherineapp.android.CABaseAct.onResume(CABaseAct.java:69) is simply: super.onResume();

I'm looking at the Android source code at http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.3_r1/android/app/Activity.java?av=f

Here is the onPause method of my HomeAct:

@Override
public void onPause() {
    super.onPause();
    this.unregisterReceiver(mMessageReceiver);
    this.unregisterReceiver(mChallengeReceiver);
}

Here's the onResume method of my HomeAct:

@Override
public void onResume() {
    super.onResume();

    refreshData();
    if (mMessageReceiver == null)
        mMessageReceiver = new MessageBroadcastReceiver();
    IntentFilter messageFilter = new IntentFilter(CAService.INTERNAL_MESSAGE_STATUS_UPDATE);
    messageFilter.setPriority(0);
    this.registerReceiver(mMessageReceiver, messageFilter);

    if (mChallengeReceiver == null)
        mChallengeReceiver = new ChallengeBroadcastReceiver();
    IntentFilter challengeFilter = new IntentFilter(CAService.INTERNAL_CHALLENGE_STATUS_UPDATE);
    challengeFilter.setPriority(0);
    this.registerReceiver(mChallengeReceiver, challengeFilter);

    showFeedbackRequest();

}

Here is the onResume implementation of CABaseAct:

@Override
public void onResume() {
    super.onResume();

    // track each Activity creation as a result event
    String activityName = this.getClass().getName().replace("com.catherineapp.android.", "");
    TrackDao.track(activityName + ".onResume");
}

The error occurs in the Activity.onResume() call, which is cascaded to through the super.onResume() calls which are the first calls I make in my overridden onResume() calls.

4

0 回答 0