0

I keep on having a NUllPointerException on the line:

return mDb.insert(DATABASE_TABLE, null, initialValues);

I don't know why. Can anyone help me? This is the SQLite database of my app:

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;
    }
1
  • What's null? At least some of the stack trace might be handy. Commented Dec 7, 2011 at 3:02

1 Answer 1

0

It seems like mDb isn't getting set. Have you called open() before calling createNote? Otherwise try adding a call to open() in the createNote method like this:

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);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.