Alex Rivera | Logout

Android error - close() was never explicitly called on database

Asked 2010-12-16T20:06:17.937
39

Where should I call close() on the code?

The LogCat returns this error:

close() was never explicitly called on database android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here

The error is this:

> 12-16 17:24:50.886: ERROR/Database(10982): close() was never explicitly called on database '/data/data/com.psyhclo/databases/calls.db' 
12-16 17:24:50.886: ERROR/Database(10982): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
12-16 17:24:50.886: ERROR/Database(10982):     at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1827)
12-16 17:24:50.886: ERROR/Database(10982):     at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:820)
12-16 17:24:50.886: ERROR/Database(10982):     at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:854)
12-16 17:24:50.886: ERROR/Database(10982):     at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:847)
12-16 17:24:50.886: ERROR/Database(10982):     at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:541)
12-16 17:24:50.886: ERROR/Database(10982):     at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
12-16 17:24:50.886: ERROR/Database(10982):     at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:118)
12-16 17:24:50.886: ERROR/Database(10982):     at com.psyhclo.CallDataHelper.<init>(CallDataHelper.java:27)
12-16 17:24:50.886: ERROR/Database(10982):     at com.psyhclo.RatedCalls.fillList(RatedCalls.java:66)
12-16 17:24:50.886: ERROR/Database(10982):     at com.psyhclo.RatedCalls.access$0(RatedCalls.java:63)
12-16 17:24:50.886: ERROR/Database(10982):     at com.psyhclo.RatedCalls$RatedCallsContentObserver.onChange(
Edit
Report

1 Answer

1

I suspect fillList() is called multiple times during a RatedCalls "session". So each time you create a new Cursor instance and call startManagingCursor() on it. Doing so you accumulate a list of Cursors - ArrayList<ManagedCursor> to be precise that is declared in ListActivity. Normally they (cursors that are being managed) will be closed automatically in ListActivity.onDestroy(). Could you confirm your RatedCalls actually passes onDestroy().

Do you override somehow the ListActivity.onDestroy() in RatedCalls. If yes, then do you call super.onDestroy() (you should call it) ?

I don't get the purpose of calling onStop() in RatedCallsContentObserver.onChange() after the fillList();. I believe Activity life-cycle callbacks should be called by OS only. So maybe calling a life-cycle callback manually you somehow prevent from onDestroy() to be called by OS (just a guess)?

UPDATE:

Dan Breslau is right - it's db object that is not closed. Sorry for misleading.

answered 2010-12-16T21:07:56.423

Your Answer