At this point I'm quite frustrated. I've been researching this for a few days and cannot even isolate anything beyond a cursor problem. I am extending ListActivity and using startManagingCursor(newcursor) in the OnCreate method. Here is the code (the database is already filled) that runs and crashes upon hitting the home button:
private void loadAlbums() {
try {
newcursor = mDbHelper.getAlbumTitlesCursor();
dbalbumadapter = new AlbumListCursorAdapter(this, newcursor);
setListAdapter(dbalbumadapter);
}
catch (SQLiteException s) {
newcursor = null;
fetchalbums = new FetchAlbumsTask().execute();
}
current_view = ALBUMTITLE_VIEW;
}
Here is the error log:
02-03 13:41:42.379: WARN/dalvikvm(340): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
02-03 13:41:42.389: ERROR/AndroidRuntime(340): Uncaught handler: thread main exiting due to uncaught exception
02-03 13:41:42.590: ERROR/AndroidRuntime(340): java.lang.RuntimeException: Unable to stop activity {com.skip.ngRCv2/com.skip.ngRCv2.ngRC}: java.lang.RuntimeException: Unable to stop activity {com.skip.ngRCv2/com.skip.ngRCv2.MusicLibraryActivity}: java.lang.NullPointerException
02-03 13:41:42.590: ERROR/AndroidRuntime(340): at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3227)
02-03 13:41:42.590: ERROR/AndroidRuntime(340): at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3272)
02-03 13:41:42.590: ERROR/AndroidRuntime(340): at android.app.ActivityThread.access$2500(ActivityThread.java:119)
02-03 13:41:42.590: ERROR/AndroidRuntime(340): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1880)
02-03 13:41:42.590: ERROR/AndroidRuntime(340): at android.os.Handler.dispatchMessage(Handler.java:99)
02-03 13:41:42.590: ERROR/AndroidRuntime(340): at android.os.Looper.loop(Looper.java:123)
02-03 13:41:42.590: ERROR/AndroidRuntime(340): at android.app.ActivityThread.main(ActivityThread.java:4363)
02-03 13:41:42.590: ERROR/AndroidRuntime(340): at java.lang.reflect.Method.invokeNative(Native Method)
02-03 13:41:42.590: ERROR/AndroidRuntime(340): at java.lang.reflect.Method.invoke(Method.java:521)
02-03 13:41:42.590: ERROR/AndroidRuntime(340): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
02-03 13:41:42.590: ERROR/AndroidRuntime(340): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
02-03 13:41:42.590: ERROR/AndroidRuntime(340): at dalvik.system.NativeStart.main(Native Method) 02-03 13:41:42.590: ERROR/AndroidRuntime(340):
Caused by: java.lang.RuntimeException: Unable to stop activity {com.skip.ngRCv2/com.skip.ngRCv2.MusicLibraryActivity}: java.lang.NullPointerException
02-03 13:41:42.590: ERROR/AndroidRuntime(340): at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3227)
02-03 13:41:42.590: ERROR/AndroidRuntime(340): at android.app.ActivityThread.performStopActivity(ActivityThread.java:3174)
02-03 13:41:42.590: ERROR/AndroidRuntime(340): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:176)
02-03 13:41:42.590: ERROR/AndroidRuntime(340): at android.app.LocalActivityManager.dispatchStop(LocalActivityManager.java:572)
02-03 13:41:42.590: ERROR/AndroidRuntime(340): at android.app.ActivityGroup.onStop(ActivityGroup.java:79)
02-03 13:41:42.590: ERROR/AndroidRuntime(340): at android.app.Instrumentation.callActivityOnStop(Instrumentation.java:1169)
02-03 13:41:42.590: ERROR/AndroidRuntime(340): at android.app.Activity.performStop(Activity.java:3797)
02-03 13:41:42.590: ERROR/AndroidRuntime(340): at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3224)
02-03 13:41:42.590: ERROR/AndroidRuntime(340): ... 11 more
02-03 13:41:42.590: ERROR/AndroidRuntime(340):
Caused by: java.lang.NullPointerException
02-03 13:41:42.590: ERROR/AndroidRuntime(340): at android.app.Activity.performStop(Activity.java:3808)
02-03 13:41:42.590: ERROR/AndroidRuntime(340): at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3224)
02-03 13:41:42.590: ERROR/AndroidRuntime(340): ... 18 more
There is a NullPointerException at Activity.performStop(Activity.java:3808), which seems to come from this method in Activity.java even though I can't cross-verify that with the line number:
final void performStop() {
if (!mStopped) {
if (mWindow != null) {
mWindow.closeAllPanels();
}
mCalled = false;
mInstrumentation.callActivityOnStop(this);
if (!mCalled) {
throw new SuperNotCalledException(
"Activity " + mComponent.toShortString() +
" did not call through to super.onStop()");
}
synchronized (mManagedCursors) {
final int N = mManagedCursors.size();
for (int i=; i<N; i++) {
ManagedCursor mc = mManagedCursors.get(i);
if (!mc.mReleased) {
mc.mCursor.deactivate();
mc.mReleased = true;
}
}
}
mStopped = true;
}
mResumed = false;
}
I have tried closing and deactivating my cursor in the OnStop method as well as setting the list adapter to null. I was under the impression that none of this was necessary when letting the activity manage the cursor as I indicated. I am passing the cursor to my custom adapter but none of the examples I've found do any managing inside the adapter.
If you can help me at least narrow down what is throwing this exception, I would be grateful!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…