Reputation: 1526
I'm just a newbie in android and trying to understand database so pls be nice.
My problem that the log is pointing is on the line where I'm calling the getWritableDatabase()
Error
private DatabaseHandler ourDb;
private static Context ourContext;
private SQLiteDatabase sdb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_menu);
ourDb = new DatabaseHandler(ourContext);
sdb =ourDb.getWritableDatabase();
and the codes in DatabaseHandler class is the one I followed in this link Tutorial
So can anybody pls tell me how to solve the error thanks!
Upvotes: 0
Views: 119
Reputation: 4499
Error is in your context. It is null
ourDb = new DatabaseHandler(ourContext);
initialize your context with
ourContext= MainActivity.this;
or pass "getApplicationContext()", "this" in your initialization
ourDb = new DatabaseHandler(MainActivity.this);
Upvotes: 2
Reputation: 152817
The Context
you passed to DatabaseHandler
is null
.
Since you seem to be in an Activity
, use this
instead of uninitialized ourContext
.
Upvotes: 1