8

当我(通过后退按钮)退出我的活动时,我的应用程序崩溃了。据我所知,这发生在 Android 代码库中,而不是我的,但我并不完全相信这一点。

这是来自 adb 的堆栈跟踪:

AndroidRuntime  E  Uncaught handler: thread main exiting due to uncaught exception
AndroidRuntime  E  java.lang.RuntimeException: Unable to stop activity {MyApp/MyApp.MainActivity}: java.lang.NullPointerException
AndroidRuntime  E      at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3097)
AndroidRuntime  E      at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3159)
AndroidRuntime  E      at android.app.ActivityThread.access$2400(ActivityThread.java:112)
AndroidRuntime  E      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1724)
AndroidRuntime  E      at android.os.Handler.dispatchMessage(Handler.java:99)
AndroidRuntime  E      at android.os.Looper.loop(Looper.java:123)
AndroidRuntime  E      at android.app.ActivityThread.main(ActivityThread.java:3948)
AndroidRuntime  E      at java.lang.reflect.Method.invokeNative(Native Method)
AndroidRuntime  E      at java.lang.reflect.Method.invoke(Method.java:521)
AndroidRuntime  E      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
AndroidRuntime  E      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
AndroidRuntime  E      at dalvik.system.NativeStart.main(Native Method)
AndroidRuntime  E  Caused by: java.lang.NullPointerException
AndroidRuntime  E      at android.app.Activity.performStop(Activity.java:3575)
AndroidRuntime  E      at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3092)
AndroidRuntime  E      ... 11 more

有人有任何想法/建议吗?

4

3 回答 3

14

帮不上什么忙,因为没有代码。还在看

引起:android.app.Activity.performStop(Activity.java:3575) 处的 java.lang.NullPointerException

我刚刚检查了 Activity.java

       final int N = mManagedCursors.size();
        for (int i=0; i<N; i++) {
            ManagedCursor mc = mManagedCursors.get(i); 
            if (!mc.mReleased) {
                mc.mCursor.deactivate(); // line 3575
                mc.mReleased = true;
            }
        }

您确定所有游标都已正确释放吗?

于 2009-09-04T05:48:31.657 回答
4

很好地解释了在这种情况下内部发生的事情:http ://www.jjoe64.com/2011/06/how-to-fix-activityperformstop.html

于 2011-11-27T11:35:38.923 回答
0

在调用 startManagingCursor() 方法之前的 Activity 中,您的 Cursor 为空。不要让光标为空。

于 2011-12-27T21:48:53.177 回答