我有一個與sqlite相關的遊標有此錯誤。我的SQLiteOpenHelper子類訪問數據庫。然後,我訪問數據庫,然後直接關閉我的光標。不過,這將導致一個錯誤,當我關閉活動:安卓&sqlite:遊標導致問題
的代碼看起來是這樣的:
String sql = "SELECT * FROM table_bla LIMIT 1";
Cursor cursor = dbHelper.getWritableDatabase().rawQuery(sql, null);
cursor.moveToFirst();
String x = cursor.getString(cursor.getColumnIndex("x"));
cursor.close();
而且我得到這個:
03-14 15:34:55.945: E/Database(3825): close() was never explicitly called on database '/data/data/my.project/databases/myDB.db'
03-14 15:34:55.945: E/Database(3825): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
03-14 15:34:55.945: E/Database(3825): at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1847)
03-14 15:34:55.945: E/Database(3825): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:820)
03-14 15:34:55.945: E/Database(3825): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:854)
03-14 15:34:55.945: E/Database(3825): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:847)
03-14 15:34:55.945: E/Database(3825): at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:572)
03-14 15:34:55.945: E/Database(3825): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
03-14 15:34:55.945: E/Database(3825): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:118)
03-14 15:34:55.945: E/Database(3825): at my.project.StartScreen.onResume(StartScreen.java:35)
03-14 15:34:55.945: E/Database(3825): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
03-14 15:34:55.945: E/Database(3825): at android.app.Activity.performResume(Activity.java:3832)
03-14 15:34:55.945: E/Database(3825): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2231)
03-14 15:34:55.945: E/Database(3825): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2256)
03-14 15:34:55.945: E/Database(3825): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1789)
03-14 15:34:55.945: E/Database(3825): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
03-14 15:34:55.945: E/Database(3825): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
03-14 15:34:55.945: E/Database(3825): at android.os.Handler.dispatchMessage(Handler.java:99)
03-14 15:34:55.945: E/Database(3825): at android.os.Looper.loop(Looper.java:130)
03-14 15:34:55.945: E/Database(3825): at android.app.ActivityThread.main(ActivityThread.java:3835)
03-14 15:34:55.945: E/Database(3825): at java.lang.reflect.Method.invokeNative(Native Method)
03-14 15:34:55.945: E/Database(3825): at java.lang.reflect.Method.invoke(Method.java:507)
03-14 15:34:55.945: E/Database(3825): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
03-14 15:34:55.945: E/Database(3825): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
03-14 15:34:55.945: E/Database(3825): at dalvik.system.NativeStart.main(Native Method)
的人都知道是什麼原因導致的?
你關閉了數據庫對象嗎? – 2012-03-14 14:40:26