android中操作SQLite常見錯誤

來源:互聯網
上載者:User

最近在改應用的一些bug,想起來可以把常見錯誤整理下,方便自己下次更快速找出錯誤原因,也給遇到同樣問題的同學提供解決思路。我會將錯誤歸類,今天先寫一點,以後再增加,歡迎指正。(為了不透漏一些資訊,log中包名被修改了)

1.
[java] 
FATAL EXCEPTION: main 
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.evaluation/com.evaluation.VehicleActivity}: android.database.sqlite.SQLiteException: unable to close due to unfinalised statements 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2781) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2797) 
    at android.app.ActivityThread.access$2300(ActivityThread.java:135) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2132) 
    at android.os.Handler.dispatchMessage(Handler.java:99) 
    at android.os.Looper.loop(Looper.java:143) 
    at android.app.ActivityThread.main(ActivityThread.java:4914) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:521) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
    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:363) 
    at android.database.sqlite.SQLiteClosable.releaseReference(SQLiteClosable.java:45) 
    at android.database.sqlite.SQLiteProgram.onAllReferencesReleased(SQLiteProgram.java:116) 
    at android.database.sqlite.SQLiteClosable.releaseReference(SQLiteClosable.java:45) 
    at android.database.sqlite.SQLiteProgram.close(SQLiteProgram.java:293) 
    at android.database.sqlite.SQLiteQuery.close(SQLiteQuery.java:133) 
    at android.database.sqlite.SQLiteCursor.close(SQLiteCursor.java:532) 
    at com.DatabaseHelper.selectAssessInformation(DatabaseHelper.java:338) 
    at com.JSKApplication.selectAssessInformation(JSKApplication.java:631) 
    at com.VehicleActivity.onCreate(VehicleActivity.java:548) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1065) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2745) 
    ... 11 more 
這個錯誤翻譯過來就是:不能關閉資料庫由於未完成的語句。
我從網上查了一下,最可能的原因是:你在操作sqlite資料庫時使用多線程了,但sqlite資料庫是不支援多線程操作,所以你必須實現多線程同步的機制。
我的程式出錯是因為:在後台啟動了個service定時向伺服器請求資料,並線上程中將資料插入資料庫。在某個時間段,使用者在向資料庫插入資料後,關閉資料庫,而此時線程正在向資料庫中寫入資料,就會造成上述異常。


作者:zj_133

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.