我有一個問題,當我使用Android的Sqlite。日誌告訴我,:SQLiteDatabase android IllegalStateException
SQLiteConnectionPool(1730): **The connection pool for /data/data/dev.xx.xx/databases/XX has been closed but there are still 1 connections in use. They will be closed as they are released back to the pool.**
08-02 14:15:41.490: D/AndroidRuntime(1730): Shutting down VM
08-02 14:15:41.490: W/dalvikvm(1730): threadid=1: thread exiting with uncaught exception (group=0xb4d74908)
08-02 14:15:41.510: E/AndroidRuntime(1730): FATAL EXCEPTION: main
08-02 14:15:41.510: E/AndroidRuntime(1730): **java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: /data/data/dev.xx.xx/databases/XX**
08-02 14:15:41.510: E/AndroidRuntime(1730): at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:55)
08-02 14:15:41.510: E/AndroidRuntime(1730): at android.database.sqlite.SQLiteDatabase.endTransaction(SQLiteDatabase.java:520)
08-02 14:15:41.510: E/AndroidRuntime(1730): at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:263)
08-02 14:15:41.510: E/AndroidRuntime(1730): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
08-02 14:15:41.510: E/AndroidRuntime(1730): at dev.xx.xx.SettingActivity$3.onClick(SettingActivity.java:205)
08-02 14:15:41.510: E/AndroidRuntime(1730): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
08-02 14:15:41.510: E/AndroidRuntime(1730): at android.os.Handler.dispatchMessage(Handler.java:99)
08-02 14:15:41.510: E/AndroidRuntime(1730): at android.os.Looper.loop(Looper.java:137)
08-02 14:15:41.510: E/AndroidRuntime(1730): at android.app.ActivityThread.main(ActivityThread.java:5039)
08-02 14:15:41.510: E/AndroidRuntime(1730): at java.lang.reflect.Method.invokeNative(Native Method)
08-02 14:15:41.510: E/AndroidRuntime(1730): at java.lang.reflect.Method.invoke(Method.java:511)
08-02 14:15:41.510: E/AndroidRuntime(1730): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
08-02 14:15:41.510: E/AndroidRuntime(1730): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
此錯誤來當我嘗試撥打:
public class DataBase extends SQLiteOpenHelper {
...
void addUser(String who, String time, String table, String phone) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_NAME, who);
values.put(KEY_PHONE, phone);
values.put(KEY_TABLE_RES, table);
values.put(KEY_TIME, time);
db.insert(TABLE_RESERVATION, null, values);
db.close(); // Closing database connection
}
....
}
我的事情是當FUNC呼叫:
this.getWritableDatabase()
這段代碼位於何處? – btse
你可以發佈你如何調用'addUser'。在調用addUser之前檢查是否已關閉,因爲logcat表示嘗試重新打開一個已關閉的對象 – Raghunandan
我這樣稱呼:\t'DataBase db = new DataBase(context); \t \t \t \t \t db.addUser(userName.getText()。的toString(),table.getText()。的toString(), \t \t \t \t \t \t \t date.getText()。的toString()+ 「」 + time.getText()。toString(),phon.getText()。toString());' – Armanoide