Cursor finalized without prior close()

android, sqlite, sqliteopenhelper

Solution

You have to close the cursor before the database. Put your code in a `try` / `catch` block and in a `finally` block, close the cursor and then close the database:

try {
    db = ...
} catch(Exception ex) { 
    // Log the exception's message or whatever you like
} finally {
    try {
      if( cursor != null && !cursor.isClosed())
        cursor.close();
       if( db.isOpen() )
        db.close();
    } catch(Exception ex) {}
}

Closing sequence matters a lot while doing IO with DB or Content Providers. For more information refer this link

Problem

I have a listview. I get data from an SQLite database. I get this error: It occurs when I go from line 20 to 21: I placed `cursor.deactivate()` and `cursor.close()` on line 50, with no result. Why I get this error and how to solve it?

Original source

Related problems