1. android.database.sqlite.SQLiteException: unable to close due to unfinalised statements


[java] view plain copy
  1. FATAL EXCEPTION: main

  2. java.lang.RuntimeException: Unable to start activity ComponentInfo{com.evaluation/com.evaluation.VehicleActivity}: android.database.sqlite.SQLiteException: unable to close due to unfinalised statements

  3. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2781)

  4. at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2797)

  5. at android.app.ActivityThread.access$2300(ActivityThread.java:135)

  6. at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2132)

  7. at android.os.Handler.dispatchMessage(Handler.java:99)

  8. at android.os.Looper.loop(Looper.java:143)

  9. at android.app.ActivityThread.main(ActivityThread.java:4914)

  10. at java.lang.reflect.Method.invokeNative(Native Method)

  11. at java.lang.reflect.Method.invoke(Method.java:521)

  12. at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)

  13. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)

  14. at dalvik.system.NativeStart.main(Native Method)

  15. Caused by: android.database.sqlite.SQLiteException: unable to close due to unfinalised statements

  16. at android.database.sqlite.SQLiteDatabase.dbclose(Native Method)

  17. at android.database.sqlite.SQLiteDatabase.onAllReferencesReleased(SQLiteDatabase.java:363)

  18. at android.database.sqlite.SQLiteClosable.releaseReference(SQLiteClosable.java:45)

  19. at android.database.sqlite.SQLiteProgram.onAllReferencesReleased(SQLiteProgram.java:116)

  20. at android.database.sqlite.SQLiteClosable.releaseReference(SQLiteClosable.java:45)

  21. at android.database.sqlite.SQLiteProgram.close(SQLiteProgram.java:293)

  22. at android.database.sqlite.SQLiteQuery.close(SQLiteQuery.java:133)

  23. at android.database.sqlite.SQLiteCursor.close(SQLiteCursor.java:532)

  24. at com.DatabaseHelper.selectAssessInformation(DatabaseHelper.java:338)

  25. at com.JSKApplication.selectAssessInformation(JSKApplication.java:631)

  26. at com.VehicleActivity.onCreate(VehicleActivity.java:548)

  27. at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1065)

  28. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2745)

  29. ... 11 more

这个错误翻译过来就是:不能关闭数据库由于未完成的语句。

我从网上查了一下,最可能的原因是:你在操作sqlite数据库时使用多线程了,但sqlite数据库是不支持多线程操作,所以你必须实现多线程同步的机制。

我的程序出错是因为:在后台启动了个service定时向服务器请求数据,并在线程中将数据插入数据库。在某个时间段,用户在向数据库插入数据后,关闭数据库,而此时线程正在向数据库中写入数据,就会造成上述异常。


2.android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed


[java] view plain copy
  1. 07-0416:18:56.677: W/System.err(29830): android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed

约束失败,导致这类错误,原因一般有两个:

1)插入的数据有一个是主键,而且插入的主键相同;

2)插入的数据有一条数据为空,而数据库中定义不能为空,也会导致这样的错误;



更多相关文章

  1. mybatisplus的坑 insert标签insert into select无参数问题的解决
  2. python起点网月票榜字体反爬案例
  3. Android教程收集贴
  4. Android(安卓)sd卡读取数据库实例代码
  5. Android中自定义对话框小结
  6. Android的ListView,数据更新后自动scroll到底部。
  7. Android中自定义对话框小结
  8. Android学习札记51:在TextView显示插入的图片
  9. Android中自定义对话框小结

随机推荐

  1. ubuntu系统下,搭建Android开发环境!!
  2. Activity详解 Intent显式跳转和隐式跳转
  3. Android面试总结(持续更新)
  4. android几种定时器机制及区别【转载】
  5. Android:CTS:解决android.carrierapi.cts.C
  6. Android: /cache中的文件是怎么消失的
  7. android apk编译打包过程
  8. Android Service详解(二)第一个Service
  9. Android系统init.rc分析
  10. Android中native进程内存泄露的调试技巧(