I sent this back in May to the Google developers group [android-developers]. I never heard back and could not reproduce the problem until one of my students did last week. I thought I posted it here and see if he calls any of the bells.
In one of my code samples, I have the following method:
static Cursor getAll(SQLiteDatabase db, String orderBy) { return(db.rawQuery("SELECT * FROM restaurants "+orderBy, null)); }
When I run it, sporadically, I get the following:
05-01 14:45:05.849: ERROR/AndroidRuntime(1145): java.lang.IllegalStateException: attempt to acquire a reference on a close SQLiteClosable 05-01 14:45:05.849: ERROR/AndroidRuntime(1145): at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:31) 05-01 14:45:05.849: ERROR/AndroidRuntime(1145): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:56) 05-01 14:45:05.849: ERROR/AndroidRuntime(1145): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:49) 05-01 14:45:05.849: ERROR/AndroidRuntime(1145): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:49) 05-01 14:45:05.849: ERROR/AndroidRuntime(1145): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1118) 05-01 14:45:05.849: ERROR/AndroidRuntime(1145): at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1092) 05-01 14:45:05.849: ERROR/AndroidRuntime(1145): at apt.tutorial.Restaurant.getAll(Restaurant.java:14)
It makes no sense to me. The database is definitely open. SQLiteClosable is SQLiteQuery created by SQLiteQueryDriver , and I see no evidence that there is a pool of objects or something is happening here that might explain how the βnewβ SQLiteClosable already closed. the fact that it is sporadic (which means that the same user interface operations are sometimes performed to throw an exception, but not always) offers some kind of pool, race state or something ... but I don't know where.
Thoughts?
Thank!
UPDATE . This code applies to the LunchList tutorials from my Android Programming Tutorials book. It is slightly decomposed and not very suitable for publishing directly to SO. You can download the code for this book from the link above if you want to take a look at it. I donβt remember exactly which edition of the textbook the student was working on at that time, although he was in Tutorial 12-Tutorial 16. I basically hoped to run into someone who had stumbled on this problem before and had a probable culprit. I am sure my database is open. Thanks again!
android
CommonsWare Sep 27 '09 at 14:02 2009-09-27 14:02
source share