1. 程式人生 > >java.lang.IllegalStateException 錯誤原因及解決方法小記

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物件,這個應當被禁止的,可以使用單例模式,使得全域性僅有一個入口可操作資料庫。