Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.illegalstateexception database not open android

Tags:

android

sqlite

When I am trying to insert to data base log cat shows an error like java.lang.illegalstateexception database not open android.

But I have opened the db using

   db = SQLiteDatabase.openDatabase(DATABASE_PATH, null,
                SQLiteDatabase.OPEN_READWRITE);

The error is not occurring frequently.Anybody know the reason for this?

like image 782
user1414146 Avatar asked May 29 '12 11:05

user1414146


2 Answers

Try it like this:

  if (!db.isOpen()) {
       db = getApplicationContext().openOrCreateDatabase(DATABASE_PATH, SQLiteDatabase.OPEN_READWRITE, null);
     }
like image 174
Simon Dorociak Avatar answered Nov 08 '22 16:11

Simon Dorociak


try

DatabaseHelper dataHelper;
SQLiteDatabase mDb;
    public DbManager openDB() throws SQLException {

    mDb = dataHelper.getWritableDatabase();
    return this;
}

and call this method where your re writing your current code.

like image 27
GAMA Avatar answered Nov 08 '22 14:11

GAMA