Android: Nullpointerexception On Getwritabledatabase()
Solution 1:
Make sure if your Context
is properly being set or not.
private Context context;
private SQLiteDatabase database;
private DatabaseHelper dbHelper;
publicUserDataAdapter(Context context) {
this.context = context;
}
public UserDataAdapter open() throws SQLException
{
dbHelper = new DatabaseHelper(context);
database = dbHelper.getWritableDatabase();
returnthis;
}
Solution 2:
FYI: I've had the NullPointerException error with a standard ContentProvider implementation. I finally solved it and the key is related to context/intent in the manifest file.
In the end I was missing this line from my inside my manifest's activity's .
<data android:mimeType="vnd.android.cursor.dir/vnd.pmp.smsmessage" />
Checkout the NotePad sample for what I am talking about. Also I prefer to use the structure here http://www.vogella.com/articles/AndroidSQLite/article.html however as his tut is designed for 3.0 had to leave out all the loader stuff for 2.2 implementation ...
After putting it in my database created and I could insert rows. I tested this simply using the onCreate for my default activity.
ContentValues values=new ContentValues();
values.put("somefieldname","somevalue");
values.put("otherfieldname","othervalue");
getContentResolver().insert(MyProvider.CONTENT_URI, values);
Solution 3:
This happens when you try to open the database from a Service or Activity constructor. Try moving the open to onCreate().
Post a Comment for "Android: Nullpointerexception On Getwritabledatabase()"