2011-12-07 131 views
0

我一直有就行了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方法是這樣開():

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); 
}