好的,首先,我知道什么是NullPointer
,但想问一下可能导致这种行为的原因。
我在Crittercism
收到了崩溃,stacktrace
指向List.add
:
java.lang.NullPointerException: Attempt to invoke interface method 'boolean java.util.List.add(java.lang.Object)' on a null object reference
at com.xxx.android.activities.SuperActivity.onCreate(SourceFile:59)
at com.xxx.android.activities.XXXActivity.onCreate(SourceFile:30)
但事实是onCreate
甚至整个SuperActivity
都没有列表。
什么可能导致stacktrace
中出现Android
这样的问题?如何找到此NullPointer
或类似来源?
修改 根据第59行的要求SuperActivity代码:
super.onCreate(savedInstanceState);
if (activitiesCreated == 0) {
isFirstStart = true;
}
activitiesCreated++;
编辑2 我知道如何关注stacktrace。我想知道的是什么可能是问题,在这样的情况下我该怎么办?
编辑3 崩溃线程的Stacktrace:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx.android/com.xxx.android.activities.XXXActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'boolean java.util.List.add(java.lang.Object)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'boolean java.util.List.add(java.lang.Object)' on a null object reference
at com.xxx.android.activities.SuperActivity.onCreate(SourceFile:59)
at com.xxx.android.activities.XXXActivity.onCreate(SourceFile:30)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
... 9 more
java.lang.NullPointerException: Attempt to invoke interface method 'boolean java.util.List.add(java.lang.Object)' on a null object reference
at com.xxx.android.activities.SuperActivity.onCreate(SourceFile:59)
at com.xxx.android.activities.XXXActivity.onCreate(SourceFile:30)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)