Android: SqLite database illegal state exception (database already closed)
<p>I have a database helper object. It is important I close it when leaving the activity, so I do. However, on returning to the activity I get a warning about querying a database that has already been closed. The query actually works, but there's still something obviously wrong.</p>

<p>My understanding of the Android activity life cycle is not strong, but I would assume I need to reopen the database in onResume(). Is this not correct?</p>

<p>Here is onResume():</p>

<pre><code>@Override
protected void onResume() {

super.onResume();

    dbHelper.setInteger(playerID);        
    dbHelper.openDataBase();
    ourCursor = dbHelper.getPlayerSavedQuestions();        
    startManagingCursor(ourCursor);
    adapter = new MyCustomAdapter(ourCursor);
    myListView.setAdapter(adapter);
}
</code></pre>

<p>Here is dbHelper.openDataBase();</p>

<pre><code>    public void openDataBase() throws SQLException {
    String myPath = DATABASE_PATH + DATABASE_NAME;
    dbSqlite = SQLiteDatabase.openDatabase(myPath, null,
            SQLiteDatabase.OPEN_READWRITE);       
}
</code></pre>

<p>Here is my logcat:</p>

<pre><code>06-15 13:51:32.388: W/SQLiteCursor(26750): requery() failed database /data/data/com.boboshi.exquizit.eng/databases/exquizit_custom.mp3 (conn# 0) already closed
06-15 13:51:32.388: W/SQLiteCursor(26750): java.lang.IllegalStateException: database /data/data/com.boboshi.exquizit.eng/databases/exquizit_custom.mp3 (conn# 0) already closed
06-15 13:51:32.388: W/SQLiteCursor(26750):  at android.database.sqlite.SQLiteDatabase.verifyDbIsOpen(SQLiteDatabase.java:2082)
06-15 13:51:32.388: W/SQLiteCursor(26750):  at android.database.sqlite.SQLiteDatabase.getDbConnection(SQLiteDatabase.java:2407)
06-15 13:51:32.388: W/SQLiteCursor(26750):  at android.database.sqlite.SQLiteDatabase.getDatabaseHandle(SQLiteDatabase.java:2388)
06-15 13:51:32.388: W/SQLiteCursor(26750):  at android.database.sqlite.SQLiteCursor.requery(SQLiteCursor.java:246)
06-15 13:51:32.388: W/SQLiteCursor(26750):  at android.app.Activity.performRestart(Activity.java:4505)
06-15 13:51:32.388: W/SQLiteCursor(26750):  at android.app.Activity.performResume(Activity.java:4531)
06-15 13:51:32.388: W/SQLiteCursor(26750):  at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2434)
06-15 13:51:32.388: W/SQLiteCursor(26750):  at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2472)
06-15 13:51:32.388: W/SQLiteCursor(26750):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1173)
06-15 13:51:32.388: W/SQLiteCursor(26750):  at android.os.Handler.dispatchMessage(Handler.java:99)
06-15 13:51:32.388: W/SQLiteCursor(26750):  at android.os.Looper.loop(Looper.java:137)
06-15 13:51:32.388: W/SQLiteCursor(26750):  at android.app.ActivityThread.main(ActivityThread.java:4424)
06-15 13:51:32.388: W/SQLiteCursor(26750):  at java.lang.reflect.Method.invokeNative(Native Method)
06-15 13:51:32.388: W/SQLiteCursor(26750):  at java.lang.reflect.Method.invoke(Method.java:511)
06-15 13:51:32.388: W/SQLiteCursor(26750):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-15 13:51:32.388: W/SQLiteCursor(26750):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-15 13:51:32.388: W/SQLiteCursor(26750):  at dalvik.system.NativeStart.main(Native Method)    
</code></pre>
