0

我正在执行以下代码:

String sql = "Select * from NetOrderID where (flag='0')";
Cursor mCur = mDb.rawQuery(sql, null) ;

日志猫:

08-16 19:09:54.868: W/System.err(10911): java.lang.NullPointerException

我不明白为什么即使此查询在实际数据库上成功执行,我也会收到此错误。

4

2 回答 2

2

mDb in the below section could possibly be null.

Cursor mCur = mDb.rawQuery(sql, null);

Make sure you are instantiating or getting an object for mDb before trying to use it.

Try something like the following:

if (mDb != null) {
    Cursor mCur = mDb.rawQuery(sql, null);
} else {
    /* handle the null scenario, instantiate an object or try and get one */
}
于 2012-08-16T13:54:55.493 回答
0

do you initialised mDb like this...?

mDb =  openOrCreateDatabase("DataBase.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);   
于 2012-08-16T13:54:12.900 回答