views:

626

answers:

1

I am experiencing a crash in my app when I quit (via the back button) out of my Activity. So far as I can tell this is happening in the Android codebase and not mine, but I'm not completely convinced of that.

Here's the stacktrace from 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

Anyone have any ideas/recommendations?

+3  A: 

Can't help much, as there's no code. Still looking at

Caused by: java.lang.NullPointerException at android.app.Activity.performStop(Activity.java:3575)

I just checked 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;
            }
        }

Are you sure all cursors are released properly?

bhatt4982
I think they should be managed by the Activity... I've called startManagingCursor() on the only Cursor I'm using. Shouldn't this handle that?
fiXedd
From the docs: This method allows the activity to take care of managing the given Cursor's lifecycle for you based on the activity's lifecycle. That is, when the activity is stopped it will automatically call deactivate() on the given Cursor, and when it is later restarted it will call requery() for you. When the activity is destroyed, all managed Cursors will be closed automatically.
fiXedd
Isn't that actually exactly what the code you posted should be doing?
fiXedd
Oh wait... I bet the cursor object IS null... duh. Thanks for pointing me in the right direction.
fiXedd
So whats the state now... fixedd????
bhatt4982
Yep, that was it. It had no problems "binding" to a null, but when it was trying to free it it was throwing an exception. Thanks.
fiXedd