Cursor finalized without prior close() Android
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
to find such problems just enable StrictMode for Debug Version like that:
public void onCreate() { if (DEVELOPER_MODE) { StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectDiskReads() .detectDiskWrites() .detectNetwork() // or .detectAll() for all detectable problems .penaltyLog() .build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() .detectLeakedSqlLiteObjects() .detectLeakedClosableObjects() .penaltyLog() .penaltyDeath() .build()); } super.onCreate(); }
more information @http://developer.android.com/reference/android/os/StrictMode.html
all the best,
Always, remember to close the cursor by calling cursor.close() before closing the database. That should fix your problem.