zxc
zxc

Reputation: 1526

Error at SQLiteOpenHelper.getWritableDatabase

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
enter image description here

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

Answers (2)

Vaibhav Agarwal
Vaibhav Agarwal

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

laalto
laalto

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

Related Questions