I read through stackoverflow about this question, and I still haven't found a solution. I noticed that sometimes the application changes this error:
java.lang.IllegalStateException: Cannot perform this operation because the connection pool has been closed. at android.database.sqlite.SQLiteConnectionPool.throwIfClosedLocked(SQLiteConnectionPool.java:962) at android.database.sqlite.SQLiteConnectionPool.waitForConnection(SQLiteConnectionPool.java:599) at android.database.sqlite.SQLiteConnectionPool.acquireConnection(SQLiteConnectionPool.java:348) at android.database.sqlite.SQLiteSession.acquireConnection(SQLiteSession.java:894) ...
I have a DatabaseHelper.java file using this approach to get an instance of it:
public static DatabaseHelper getInstance(Context context) { if (mInstance == null) { mInstance = new DatabaseHelper(context.getApplicationContext()); } return mInstance; }
Then I have methods like this (that it crashed in the line cursor.moveToFirst () with this error). It almost never crashes, but sometimes it happens.
public Profile getProfile(long id) { SQLiteDatabase db = this.getReadableDatabase(); String selectQuery = "SELECT * FROM " + TABLE_PROFILES + " WHERE " + KEY_PROFILES_ID + " = " + id; Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list Profile profile = new Profile(); if (cursor.moveToFirst()) { doWhatEver(); } cursor.close(); db.close(); return profile; }
So that he uses all the methods that I use:
SQLiteDatabase db = this.getReadableDatabase(); (or Writable)
And then I close the cursor and db. In this case, the error hit the line:
cursor.moveToFirst();
I don’t understand why the error says that db is closing if I call this.getReadableDatabase () earlier. Please Support! Thank:)
java android database sqlite singleton
Ferran Negre Apr 25 '14 at 12:44 2014-04-25 12:44
source share