0

我的 android 应用程序正在使用手机的 SQLiteDatabase。似乎在应用程序崩溃的某个时刻,我的很多页面/片段突然无法工作,因为数据库被永久锁定。

有没有办法手动解锁/消除问题,以便我可以再次开始访问我的其他功能?相同的代码在我其他朋友的手机上工作,所以我相信我需要在我自己的手机上手动解锁数据库才能再次进行调试。

如果有帮助,以下是我的(已编辑:完整)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 
4

2 回答 2

1

发生这种情况的原因是您一次只能打开一个与数据库的连接。我相信您没有关闭 Db 连接,或者当您尝试写入 Db 时,某个线程已经在写入 Db。

我建议您从一个 SQLOpenHelper 访问 db(请参见此示例),或者确保在完成所有 db 助手实例后关闭它们。

于 2013-02-08T03:02:38.093 回答
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.

这个问题通常是一个线程试图访问数据库,但另一个线程拥有锁或正在使用它。解决方案:在应用程序中仅使用一个连接到数据库的实例。一种方法可以将实例存储在子应用程序类中。

于 2013-02-08T03:04:18.067 回答