天天看點

java.lang.IllegalStateException 錯誤原因及解決方法小記

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)

at android.database.sqlite.SQLiteSession.executeForCursorWindow(SQLiteSession.java:834)

at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:62)

at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:144)

at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:133)

在項目中遇到如上描述問題,連續調用連個線程操作資料庫時引起的。

出現多個sqlliteopenhelper 及産生多個connection對象,這個應當被禁止的,可以使用單例模式,使得全局僅有一個入口可操作資料庫。

繼續閱讀