我正在使用 sqlite db 并使用 Alex LockWood 的一些代码正确管理您的 SQLite 数据库
它工作得很好,但有时我得到了错误"java.lang.IllegalStateException: Cannot perform this operation because the connection pool has been closed."
这是完整的错误:
02-20 16:37:21.385: W/dalvikvm(25730): threadid=13: thread exiting with uncaught exception (group=0x41c122a0)
02-20 16:37:21.390: E/AndroidRuntime(25730): FATAL EXCEPTION: Timer-0
02-20 16:37:21.390: E/AndroidRuntime(25730): java.lang.IllegalStateException: Cannot perform this operation because the connection pool has been closed.
02-20 16:37:21.390: E/AndroidRuntime(25730): at android.database.sqlite.SQLiteConnectionPool.throwIfClosedLocked(SQLiteConnectionPool.java:963)
02-20 16:37:21.390: E/AndroidRuntime(25730): at android.database.sqlite.SQLiteConnectionPool.waitForConnection(SQLiteConnectionPool.java:678)
02-20 16:37:21.390: E/AndroidRuntime(25730): at android.database.sqlite.SQLiteConnectionPool.acquireConnection(SQLiteConnectionPool.java:349)
02-20 16:37:21.390: E/AndroidRuntime(25730): at android.database.sqlite.SQLiteSession.acquireConnection(SQLiteSession.java:894)
02-20 16:37:21.390: E/AndroidRuntime(25730): at android.database.sqlite.SQLiteSession.executeForCursorWindow(SQLiteSession.java:834)
02-20 16:37:21.390: E/AndroidRuntime(25730): at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:62)
02-20 16:37:21.390: E/AndroidRuntime(25730): at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:143)
02-20 16:37:21.390: E/AndroidRuntime(25730): at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:133)
02-20 16:37:21.390: E/AndroidRuntime(25730): at com.uit.pokemon.DatabaseHandler.getStadiumStatusById(DatabaseHandler.java:533)
02-20 16:37:21.390: E/AndroidRuntime(25730): at playground.RoomActivity.checkTable(RoomActivity.java:276)
02-20 16:37:21.390: E/AndroidRuntime(25730): at playground.RoomActivity$6.run(RoomActivity.java:321)
02-20 16:37:21.390: E/AndroidRuntime(25730): at java.util.Timer$TimerImpl.run(Timer.java:284)
02-20 16:37:21.460: I/timertask cancel(25730): canceled
这是导致错误的代码:
public int getStadiumStatusById(int dataStadiumId){
SQLiteDatabase db = this.getReadableDatabase();
Cursor cur = db.rawQuery("SELECT " + keyStadiumId + " as _id, "
+ keyRoomName + ", " + keyP1Name + ", " + keyP1PokemonName
+ ", " + keyP1PokemonLevel + ", " + keyP1PokemonHp + ", "
+ keyP2Name + ", " + keyP2PokemonName + ", "
+ keyP2PokemonLevel + ", " + keyP2PokemonHp + ", "
+ keyTimeCreate + ", " + keyStadiumStatus + " from "
+ tbl_stadium + " WHERE " + keyStadiumId + " = " + "'"
+ dataStadiumId + "'", new String[] {});
int stadiumStatus = 0;
if(cur.getCount()>0)
{
cur.moveToFirst();
stadiumStatus = cur.getInt(11);
}
db.close();
cur.close();
return stadiumStatus;
}
我用谷歌搜索了好几个小时,但没有结果。请帮我修复它。任何帮助将不胜感激。谢谢!