Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting java.lang.IllegalStateException: attempt to re-open an already-closed object: when using cursor in Android
    text
    copied!<p>I am using Cursor to get data from DB (it's information about the overlay markers on Map). I am loading a map with help of this data. Interaction with the DB through Cursor is done in a asyncTask.</p> <p>Now here is the problem I am facing. If I press back button while the cursor is running to load the map (i.e. in middle of loading overlay markers in a while loop) I get this error:</p> <pre><code>Caused by: java.lang.IllegalStateException: attempt to re-open an already-closed object: android.database.sqlite.SQLiteQuery (mSql = SELECT _id, category, latitude, longitude FROM node) </code></pre> <p>Here is the complete trace of it:</p> <pre><code>12-21 11:11:30.173: E/AndroidRuntime(2824): FATAL EXCEPTION: AsyncTask #5 12-21 11:11:30.173: E/AndroidRuntime(2824): java.lang.RuntimeException: An error occured while executing doInBackground() 12-21 11:11:30.173: E/AndroidRuntime(2824): at android.os.AsyncTask$3.done(AsyncTask.java:200) 12-21 11:11:30.173: E/AndroidRuntime(2824): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273) 12-21 11:11:30.173: E/AndroidRuntime(2824): at java.util.concurrent.FutureTask.setException(FutureTask.java:124) 12-21 11:11:30.173: E/AndroidRuntime(2824): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307) 12-21 11:11:30.173: E/AndroidRuntime(2824): at java.util.concurrent.FutureTask.run(FutureTask.java:137) 12-21 11:11:30.173: E/AndroidRuntime(2824): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068) 12-21 11:11:30.173: E/AndroidRuntime(2824): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561) 12-21 11:11:30.173: E/AndroidRuntime(2824): at java.lang.Thread.run(Thread.java:1102) 12-21 11:11:30.173: E/AndroidRuntime(2824): Caused by: java.lang.IllegalStateException: attempt to re-open an already-closed object: android.database.sqlite.SQLiteQuery (mSql = SELECT _id, category, latitude, longitude FROM node) 12-21 11:11:30.173: E/AndroidRuntime(2824): at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:34) 12-21 11:11:30.173: E/AndroidRuntime(2824): at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:64) 12-21 11:11:30.173: E/AndroidRuntime(2824): at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:299) 12-21 11:11:30.173: E/AndroidRuntime(2824): at android.database.sqlite.SQLiteCursor.onMove(SQLiteCursor.java:271) 12-21 11:11:30.173: E/AndroidRuntime(2824): at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:188) 12-21 11:11:30.173: E/AndroidRuntime(2824): at android.database.AbstractCursor.moveToNext(AbstractCursor.java:256) 12-21 11:11:30.173: E/AndroidRuntime(2824): at org.mid.kew.activities.MapPageActivity$MapLoadingAsyncTask.doInBackground(MapPageActivity.java:632) 12-21 11:11:30.173: E/AndroidRuntime(2824): at org.mid.kew.activities.MapPageActivity$MapLoadingAsyncTask.doInBackground(MapPageActivity.java:1) 12-21 11:11:30.173: E/AndroidRuntime(2824): at android.os.AsyncTask$2.call(AsyncTask.java:185) 12-21 11:11:30.173: E/AndroidRuntime(2824): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) 12-21 11:11:30.173: E/AndroidRuntime(2824): ... 4 more </code></pre> <p>and here is a snapshot of code I am using in asyncTask</p> <p>Under DoInBackground method</p> <pre><code>openKewDataBase(); Cursor cursor = getCursorForOverLayIcons(); startManagingCursor(cursor); cursor.moveToFirst(); while (!cursor.isAfterLast()) { ... cursor.moveToNext(); } cursor.close(); </code></pre> <p>Under onPostExecute Method</p> <pre><code>.... closeKewDataBase(); </code></pre> <p>As per I can trace Its crashing at "cursor.moveToNext();"</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload