开发者

Why SQLiteQueryBuilder throws a NullPointerException in computeProjection() after Activity.onRestart()?

In my Activity.onCreate() I call AsyncQueryHandler.startQuery() and it returns a valid Cursor which I use to populate a SimpleCursorAdapter. But after pressing home button and then launching my application again through onRestart() I do the same query, but I get the following Exception.

W/System.err(29512): java.lang.NullPointe开发者_StackOverflowrException
W/System.err(29512):    at android.database.sqlite.SQLiteQueryBuilder.computeProjection(SQLiteQueryBuilder.java:516)
W/System.err(29512):    at android.database.sqlite.SQLiteQueryBuilder.buildQuery(SQLiteQueryBuilder.java:370)
W/System.err(29512):    at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:323)
W/System.err(29512):    at com.voidgroup.attention.data.EntryDatabase.query(EntryDatabase.java:177)
W/System.err(29512):    at com.voidgroup.attention.data.EntryDatabase.getNotes(EntryDatabase.java:100)
W/System.err(29512):    at com.voidgroup.attention.data.AttentionProvider.query(AttentionProvider.java:114)
W/System.err(29512):    at android.content.ContentProvider$Transport.query(ContentProvider.java:163)
W/System.err(29512):    at android.content.ContentResolver.query(ContentResolver.java:245)
W/System.err(29512):    at android.content.AsyncQueryHandler$WorkerHandler.handleMessage(AsyncQueryHandler.java:79)
W/System.err(29512):    at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err(29512):    at android.os.Looper.loop(Looper.java:123)
W/System.err(29512):    at android.os.HandlerThread.run(HandlerThread.java:60)

My ContentProvider creates a wrapper class EntryDatabase in its onCreate() as follows

@Override
public boolean onCreate() {
    db = new EntryDatabase(getContext());
    return true;
}

And the EntryDatabase constructor is like this

public EntryDatabase(Context context) {
    helper = new EntrySQLiteHelper(context);
}

EntryDatabase.query essentially does this after setting up the SQLiteQueryBuilder

cursor = qb.query(helper.getReadableDatabase(), columns, selection, selectionArgs, null, null, sortOrder, lim);


From Android source I checked that NullPointerException in computeProjection was because of a projection String array had a null cell. I tried to be clever and fix columns given by user by adding a table name when performing a join operation. This was fine as long as I gave the columns array as new String[] { }, but then I changed to use static final String[] so first call to ContentResolver query succeeded, but the second one used a modified table names "constant" thus breaking my queries.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜