我的Android应用程序正在使用手机的SQLiteDatabase。似乎在应用程序崩溃的某个时刻,突然很多我的页面/片段无法正常工作,因为数据库被永久锁定。
有没有办法手动解锁/删除问题,以便我可以再次开始访问我的其他功能?相同的代码可以在我的其他朋友的手机上使用,所以我相信我需要在我自己的手机上手动解锁数据库,以便再次进行调试。
以下是我的(编辑:FULL)logcat,如果它有帮助:
02-08 11:15:34.880: E/SqliteDatabaseCpp(10363): sqlite3_exec - Failed to set synchronous mode = 1(Normal)
02-08 11:15:34.895: E/SQLiteDatabase(10363): Failed to open the database. closing it.
02-08 11:15:34.895: E/SQLiteDatabase(10363): android.database.sqlite.SQLiteDatabaseLockedException: database is locked
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1132)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1083)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1170)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:844)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:228)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:157)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at com.sqlite.database.PlaceDataSource.open(PlaceDataSource.java:26)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at com.activities.TravelogueListBaseAdapter.getView(TravelogueListBaseAdapter.java:163)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:220)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.widget.AbsListView.obtainView(AbsListView.java:2197)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.widget.ListView.measureHeightOfChildren(ListView.java:1244)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.widget.ListView.onMeasure(ListView.java:1155)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.view.View.measure(View.java:12929)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4703)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1385)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.widget.LinearLayout.measureVertical(LinearLayout.java:670)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.widget.LinearLayout.onMeasure(LinearLayout.java:563)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.view.View.measure(View.java:12929)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4703)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.view.View.measure(View.java:12929)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4703)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.view.View.measure(View.java:12929)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:594)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:376)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.view.View.measure(View.java:12929)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4703)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1385)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1027)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.widget.LinearLayout.onMeasure(LinearLayout.java:565)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.view.View.measure(View.java:12929)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at shared.ui.actionscontentview.ActionsContentView.onMeasure(ActionsContentView.java:259)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.view.View.measure(View.java:12929)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:594)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:376)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.view.View.measure(View.java:12929)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4703)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.view.View.measure(View.java:12929)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.widget.LinearLayout.measureVertical(LinearLayout.java:822)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.widget.LinearLayout.onMeasure(LinearLayout.java:563)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.view.View.measure(View.java:12929)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4703)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2257)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.view.View.measure(View.java:12929)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1240)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2628)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.os.Handler.dispatchMessage(Handler.java:99)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.os.Looper.loop(Looper.java:137)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at android.app.ActivityThread.main(ActivityThread.java:4511)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at java.lang.reflect.Method.invokeNative(Native Method)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at java.lang.reflect.Method.invoke(Method.java:511)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
02-08 11:15:34.895: E/SQLiteDatabase(10363): at dalvik.system.NativeStart.main(Native Method)
02-08 11:15:34.900: E/AndroidRuntime(10363): FATAL EXCEPTION: main
02-08 11:15:34.900: E/AndroidRuntime(10363): android.database.sqlite.SQLiteDatabaseLockedException: database is locked
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1132)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1083)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1170)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:844)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:228)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:157)
02-08 11:15:34.900: E/AndroidRuntime(10363): at com.sqlite.database.PlaceDataSource.open(PlaceDataSource.java:26)
02-08 11:15:34.900: E/AndroidRuntime(10363): at com.activities.TravelogueListBaseAdapter.getView(TravelogueListBaseAdapter.java:163)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:220)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.widget.AbsListView.obtainView(AbsListView.java:2197)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.widget.ListView.measureHeightOfChildren(ListView.java:1244)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.widget.ListView.onMeasure(ListView.java:1155)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.view.View.measure(View.java:12929)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4703)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1385)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.widget.LinearLayout.measureVertical(LinearLayout.java:670)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.widget.LinearLayout.onMeasure(LinearLayout.java:563)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.view.View.measure(View.java:12929)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4703)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.view.View.measure(View.java:12929)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4703)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.view.View.measure(View.java:12929)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:594)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:376)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.view.View.measure(View.java:12929)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4703)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1385)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1027)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.widget.LinearLayout.onMeasure(LinearLayout.java:565)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.view.View.measure(View.java:12929)
02-08 11:15:34.900: E/AndroidRuntime(10363): at shared.ui.actionscontentview.ActionsContentView.onMeasure(ActionsContentView.java:259)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.view.View.measure(View.java:12929)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:594)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:376)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.view.View.measure(View.java:12929)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4703)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.view.View.measure(View.java:12929)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.widget.LinearLayout.measureVertical(LinearLayout.java:822)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.widget.LinearLayout.onMeasure(LinearLayout.java:563)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.view.View.measure(View.java:12929)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4703)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
02-08 11:15:34.900: E/AndroidRuntime(10363): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2257)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.view.View.measure(View.java:12929)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1240)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2628)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.os.Handler.dispatchMessage(Handler.java:99)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.os.Looper.loop(Looper.java:137)
02-08 11:15:34.900: E/AndroidRuntime(10363): at android.app.ActivityThread.main(ActivityThread.java:4511)
02-08 11:15:34.900: E/AndroidRuntime(10363): at java.lang.reflect.Method.invokeNative(Native Method)
02-08 11:15:34.900: E/AndroidRuntime(10363): at java.lang.reflect.Method.invoke(Method.java:511)
02-08 11:15:34.900: E/AndroidRuntime(10363): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
02-08 11:15:34.900: E/AndroidRuntime(10363): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
02-08 11:15:34.900: E/AndroidRuntime(10363): at dalvik.system.NativeStart.main(Native Method)
02-08 11:15:34.920: E/android.os.Debug(1981): !@Dumpstate > dumpstate -k -t -n -z -d -o /data/log/dumpstate_app_error
02-08 11:15:35.420: E/lights(1981): write_int: path
答案 0 :(得分:1)
发生这种情况的原因是因为您一次只能打开一个数据库连接。我相信你没有关闭Db连接,或者当你试图写入它时,某些线程已经写入Db。
我建议您从一个SQLOpenHelper(See this example)访问db,或者确保在完成db helper之后关闭所有db helper实例。
答案 1 :(得分:1)
当您关闭应用程序(或系统将其关闭)时,您的数据库连接将被断开并清除。因此,没有“永久锁定”这样的东西。
02-08 10:40:24.195: E/SqliteDatabaseCpp(7212): sqlite3_exec - Failed to set synchronous mode = 1(Normal)
02-08 10:40:24.205: E/SQLiteDatabase(7212): Failed to open the database. closing it.
这个问题通常是一个线程试图访问数据库,但另一个线程有锁或正在使用它。解决方案:在应用程序中仅使用一个连接到数据库的实例。 一种方法是将实例存储在subbed的Application类中。