5

Yesterday the application was working normally, and i didn't edit my codes. But now its not working. the logcat is

close() was never explicitly called on database '/data/data/[myproject]/databases/MyDB' 
android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1943)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1007)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:986)
at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1051)
at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:770)
at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:221)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:157)
at mn.emondo.parliament.DBAdapter.open(DBAdapter.java:46)
at mn.emondo.parliament.ProfileActivity.onCreate(ProfileActivity.java:46)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
2
  • You need to check in ProfileActivity.java:46 and DBAdapter.java:46 .You forgot to call database call function ,which may be you have use in 'ProfileActivity.java:46' to open database.
    – Herry
    Mar 30, 2012 at 9:05
  • Show you code will give us more specification how you do Database open and close.
    – Herry
    Mar 30, 2012 at 10:28

5 Answers 5

2

Once you open the database and cursor you must close these two before exiting from the class or activity. db.close(); cr.close();

please use this.

1

You haven't Closed the Cursor. It is Written in your ERROR.

Application did not close the cursor or database object that was opened here

So as as i can't see your code, just check you haven't Closed your Cursor.

Or Try to Clean your Project and Re-Build it.

1

You forgot to close() your database; the next time it is opened you'll receive a DatabaseObjectNotClosedException exception.

1

If it was working previously and not now ,, try changing the version name of the database,,,

even after if it doesn't work , then change the version name and the database name .

1

Try this method when you finish fetching data from database..
When you open database you need to call db.open() and when you finish your database work you need to call close() method. use following method.

db.close();

and you must call to open database from your Activity.java

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.