Reputation: 31973
I have few activities that make use of sqlite database, there is use of Cursors of course but in every method where I use cursors I close them consistently . . . well even I do the closing of the cursors still I get this message
I/dalvikvm( 5232): at android.database.sqlite.SQLiteCursor.finalize(SQLiteCursor.java:631)
I/dalvikvm( 5232): at dalvik.system.NativeStart.run(Native Method)
I/dalvikvm( 5232): Uncaught exception thrown by finalizer (will be discarded):
I/dalvikvm( 5232): Ljava/lang/IllegalStateException;: Finalizing cursor android.database.sqlite.SQLiteCursor@467ed108 on my_table_name that has not been deactivated or closed
What exactly is my problem ? how can I find where is the bug in my code ? should "(SQLiteCursor.java:631)" mean something to me ?
Thanks
Upvotes: 0
Views: 1306
Reputation: 6710
I've also just fixed this error across my app. When I was doing fetch calls with cursors I was doing checks like:
if (mCursor != null && Cursor.getCount() > 0) {
//Iterate through cursor list
mCursor.close();
}
Which causes this error because you still need to close the cursor even if getCount() == 0. The logic should be:
if (mCursor != null) {
if(mCursor.getCount() > 0) {
//Iterate through cursor list
}
mCursor.close();
}
Hope that helps someone.
Upvotes: 0
Reputation: 1207
I have gotten this error when a thread terminates due to an error and closes the activity prematurely along with it. It could be that is what is happening. You might want want to check out the logcat output above the error to see if another error is causing the thread to end the activity and thus generate the extra error.
Upvotes: 0
Reputation: 16194
You have closed DB connection but not closed cursor
when ever closed DB connection first check Cursor like that ..
Cursor c;
if (c != null) {
c.deactivate();
c.close();
}
Upvotes: 0
Reputation: 30168
No, but this one
android.database.sqlite.SQLiteCursor@467ed108
could help you figure out which one is the one that has not been closed properly. You can log the cursor's reference and you will get a similar string as above, e.g.:
Log.d("ActivityX", cursor1);
Upvotes: 1