Skip to content Skip to sidebar Skip to footer

Don't Have Database Lock! In Android

I've been getting this error recently I know the cause but i don't know how to fix it. here is the error from the logcat: 10-05 02:34:00.177: E/SQLiteDatabase(1111): close() was ne

Solution 1:

It seems that you never close ourDatabase in SQLHandler.close().

publicvoidclose() {
    ourDatabase.close();// may be you should add this
    ourHelper.close();
}

What's more, I think you should reuse the SQLHandler object, just make it as a field variable. The problems may be caused by frequent open/close.

Solution 2:

I found out that if your using open() and close() many time there is a change that your program will not be able to handle it, so my advice is to create only one instance of your SQLiteOpenHelper open() and close() so what I did is that i created one SQLHandler something like this.

SQLHandlernewentry=newSQLHandler(context);
newentry.open();

and then insert this code to onResume() and onPause()

@Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        newentry.open();
    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        newentry.close();
    }

Post a Comment for "Don't Have Database Lock! In Android"