Why is my activity crashing when hitting the home button?

被刻印的时光 ゝ 提交于 2019-11-29 11:47:54

If this is the right rev, line 3808 corresponds to:

[[ I know its not the official android source, but the line number lines up]]

http://code.google.com/p/pdn-slatedroid/source/browse/trunk/eclair/frameworks/base/core/java/android/app/Activity.java?r=12#3808

mc.mCursor.deactivate();

As far as I can tell, mc cannot ever be null. It seems that mCursor (which is final) can be null only if a null cursor was passed into startManagingCursor(). I captured my notes before for others to confirm this.

Can you log your cursor is just before you pass it into startManagingCursor()? I'd be curious what the last occurrence of that message before the crash says.

You have this line when there's a sql exception:

newcursor = null;

I wonder if that's getting into the startManagingCursor() call.


Notes:

  • startManagingCursor() creates a ManagedCursor:

http://code.google.com/p/pdn-slatedroid/source/browse/trunk/eclair/frameworks/base/core/java/android/app/Activity.java?r=12#1549

public void startManagingCursor(Cursor c) {
    synchronized (mManagedCursors) {
        mManagedCursors.add(new ManagedCursor(c));
    }
}
  • ManagedCursor sets final field mCursor:

http://code.google.com/p/pdn-slatedroid/source/browse/trunk/eclair/frameworks/base/core/java/android/app/Activity.java?r=12#647

private static final class ManagedCursor {
    ManagedCursor(Cursor cursor) {
        mCursor = cursor;
        mReleased = false;
        mUpdated = false;
    }

    private final Cursor mCursor;
    private boolean mReleased;
    private boolean mUpdated;
}
  • All the internal calls to startManagingCursor() are guarded, e.g.:

http://code.google.com/p/pdn-slatedroid/source/browse/trunk/eclair/frameworks/base/core/java/android/app/Activity.java?r=12#1465

if (c != null) {
    startManagingCursor(c);
}
return c;

Start your app in a debugger, set an exception breakpoint on NPE and then see where it is bailing out.

Should give you an idea what is going on.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!