title: Exception: attempt to acquire a reference on a close SQLiteClosable
body: <p>I posted <a href="http://groups.google.com/group/android-developers/browse_thread/thread/1678a8b9bc7b6a8a" rel="noreferrer">this</a> back in May on the [android-developers] Google Group. I never heard back and was not able to reproduce the problem until one of my students did last week. I figured I'd post it here and see if it rang any bells for anyone.</p>
  
  <p>In one of my code samples, I have the following method:</p>
  
  <pre><code>static Cursor getAll(SQLiteDatabase db, String orderBy) {
          return(db.rawQuery("SELECT * FROM restaurants "+orderBy, null));
  
  }
  </code></pre>
  
  <p>When I run it, sporadically, I get this:</p>
  
  <pre><code>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.&lt;init&gt;(SQLiteProgram.java:56)
  05-01 14:45:05.849: ERROR/AndroidRuntime(1145):     at
  android.database.sqlite.SQLiteQuery.&lt;init&gt;(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)
  </code></pre>
  
  <p>This makes no sense to me. The database is definitely open. The
  <code>SQLiteClosable</code> is the <code>SQLiteQuery</code> created by <code>SQLiteQueryDriver</code>, and I
  see no evidence that there is an object pool or something going on here
  that might explain how a "new" <code>SQLiteClosable</code> is already closed. The
  fact that it is sporadic (meaning the same UI operations sometimes
  trigger the exception, but not always) suggests some sort of pool, race
  condition, or something...but I'm not sure where. </p>
  
  <p>Thoughts?</p>
  
  <p>Thanks!</p>
  
  <p><strong>UPDATE</strong>: The code in question is from the LunchList tutorials out of my <a href="http://commonsware.com/AndTutorials/" rel="noreferrer">Android Programming Tutorials</a> book. It's a bit spread out and not terribly suitable for posting directly in SO. You can download the code for that book from the above link if you want to take a look at it. I do not recall exactly which edition of the tutorial the student was working on at the time, though it was in the Tutorial 12-Tutorial 16 range. I was mostly hoping to run across somebody who had tripped over this problem before and had a likely culprit. I'm fairly certain my database is open. Thanks again!</p>