我继续在NUllPointerException
上线:
return mDb.insert(DATABASE_TABLE, null, initialValues);
我不知道为什么。谁能帮我?这是我的应用程序的SQLite数据库:
public MessagesDBAdapter open() throws SQLException {
mDbHelper = new DatabaseHelper(mCtx);
mDb = mDbHelper.getWritableDatabase();
return this;
}
public void close() {
mDbHelper.close();
}
public long createNote(String phoneNo, String message) {
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_RECIPIENT, phoneNo);
initialValues.put(KEY_MESSAGE, message);
return mDb.insert(DATABASE_TABLE, null, initialValues);
}
public boolean deleteNote(long rowId) {
return mDb.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0;
}
答案 0 :(得分:1)
似乎mDb没有设置好。你在调用createNote之前调用了open()吗?否则,尝试在createNote方法中添加对open()的调用,如下所示:
public long createNote(String phoneNo, String message) {
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_RECIPIENT, phoneNo);
initialValues.put(KEY_MESSAGE, message);
open();
return mDb.insert(DATABASE_TABLE, null, initialValues);
}