我在“MainActivity”(A)和“FindActivity”(B)中有 DoubleClick 横幅。当我单击 A 中的横幅时 - 它会打开并且我正在按下“返回”按钮 - A 再次出现并且工作正常。当单击 B 中的横幅时 - 它会打开并且我正在按“返回” - B 没有出现。LogCat 说:
05-29 16:38:27.542: E/AndroidRuntime(661): FATAL EXCEPTION: main
05-29 16:38:27.542: E/AndroidRuntime(661): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.my.myapp/com.my.myapp.FindActivity}: java.lang.NullPointerException
05-29 16:38:27.542: E/AndroidRuntime(661): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
05-29 16:38:27.542: E/AndroidRuntime(661): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
05-29 16:38:27.542: E/AndroidRuntime(661): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-29 16:38:27.542: E/AndroidRuntime(661): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
05-29 16:38:27.542: E/AndroidRuntime(661): at android.os.Handler.dispatchMessage(Handler.java:99)
05-29 16:38:27.542: E/AndroidRuntime(661): at android.os.Looper.loop(Looper.java:130)
05-29 16:38:27.542: E/AndroidRuntime(661): at android.app.ActivityThread.main(ActivityThread.java:3687)
05-29 16:38:27.542: E/AndroidRuntime(661): at java.lang.reflect.Method.invokeNative(Native Method)
05-29 16:38:27.542: E/AndroidRuntime(661): at java.lang.reflect.Method.invoke(Method.java:507)
05-29 16:38:27.542: E/AndroidRuntime(661): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
05-29 16:38:27.542: E/AndroidRuntime(661): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
05-29 16:38:27.542: E/AndroidRuntime(661): at dalvik.system.NativeStart.main(Native Method)
05-29 16:38:27.542: E/AndroidRuntime(661): Caused by: java.lang.NullPointerException
05-29 16:38:27.542: E/AndroidRuntime(661): at com.my.myapp.FindActivity.onCreate(FindActivity.java:125)
05-29 16:38:27.542: E/AndroidRuntime(661): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-29 16:38:27.542: E/AndroidRuntime(661): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
05-29 16:38:27.542: E/AndroidRuntime(661): ... 11 more
我在第 125 行设置了断点。惊喜 - LogCat 显示异常但未到达断点。onCreate 中的代码是:
super.onCreate(savedInstanceState);//line124
m_current = MyApp.sInstance.GetName();//line 125 ========
更新 sInstance 是 App 单例。添加了正确的日志副本
Update2 提供了更大的堆栈跟踪