我有以下代碼:爲什麼有些用戶在database.close上獲得FC?
public class DbAdapter {
...
public DbAdapter open() throws SQLException {
mDbHelper = new DatabaseHelper(mCtx);
mDb = mDbHelper.getWritableDatabase();
return this;
}
public void close() {
mDbHelper.close();
}
...
此調用close方法在MainActivity中的onDestroy:
@Override
protected void onDestroy() {
super.onDestroy();
mDbHelper.close();
}
我得從我的用戶以下錯誤日誌:
device_model:bravo
build_version:1.6.17
condition:1
processName:spb.bridges
pid:23493
uid:10057
tag:null
shortMsg:android.database.sqlite.SQLiteException
longMsg:android.database.sqlite.SQLiteException: unable to close due to unfinalised statements
stackTrace:java.lang.RuntimeException: Unable to destroy activity {my.package/my.package.MainActivity}: android.database.sqlite.SQLiteException: unable to close due to unfinalised statements
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:2680)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:2698)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:2814)
at android.app.ActivityThread.access$1600(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3694)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.database.sqlite.SQLiteException: unable to close due to unfinalised statements
at android.database.sqlite.SQLiteDatabase.dbclose(Native Method)
at android.database.sqlite.SQLiteDatabase.onAllReferencesReleased(SQLiteDatabase.java:323)
at android.database.sqlite.SQLiteDatabase.close(SQLiteDatabase.java:884)
at android.database.sqlite.SQLiteOpenHelper.close(SQLiteOpenHelper.java:220)
at spb.bridges.DbAdapter.close(DbAdapter.java:177)
at spb.bridges.MainActivity.onDestroy(MainActivity.java:159)
我的代碼有什麼問題?
應該捕捉什麼樣的異常? –
'SQLiteException'或'Exception'本身。這是不好的做法,但比扔掉「關閉」力量要好。其根本原因可能是它試圖在'.close()'時執行數據庫操作。你有長時間運行的DB操作嗎? – Haphazard