2011-12-29 64 views
0

我在应用程序中收到来自零星SQLiteException的崩溃报告。我并不直接与SQLite数据库进行交互。我已将代码追踪到WebView小部件的使用情况。例外的原因不同,但有一对夫妇的例子如下...Android WebView抛出SQLiteException

android.database.sqlite.SQLiteException: database is locked: BEGIN EXCLUSIVE; 
at android.database.sqlite.SQLiteDatabase.native_execSQL(Native Method) 
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1768) 
at android.database.sqlite.SQLiteDatabase.beginTransactionWithListener(SQLiteDatabase.java:558) 
at android.database.sqlite.SQLiteDatabase.beginTransaction(SQLiteDatabase.java:512) 
at android.webkit.WebViewDatabase.startCacheTransaction(WebViewDatabase.java:603) 
at android.webkit.CacheManager.enableTransaction(CacheManager.java:251) 
at android.webkit.WebViewWorker.handleMessage(WebViewWorker.java:214) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:143) 
at android.os.HandlerThread.run(HandlerThread.java:60) 

另一个例子......

java.lang.RuntimeException: Unable to create application com.example.MyApplication: android.database.sqlite.SQLiteException: near "VALUES": syntax error: , while compiling: INSERT INTO cache (VALUES (
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3828) 
at android.app.ActivityThread.access$2200(ActivityThread.java:132) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1082) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:150) 
at android.app.ActivityThread.main(ActivityThread.java:4293) 
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:839) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: android.database.sqlite.SQLiteException: near "VALUES": syntax error: , while compiling: INSERT INTO cache (VALUES (
at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method) 
at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92) 
at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:65) 
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83) 
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:41) 
at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1231) 
at android.database.DatabaseUtils$InsertHelper.getStatement(DatabaseUtils.java:858) 
at android.database.DatabaseUtils$InsertHelper.getColumnIndex(DatabaseUtils.java:904) 
at android.webkit.WebViewDatabase.getInstance(WebViewDatabase.java:397) 
at android.webkit.WebView.<init>(WebView.java:1077) 
at android.webkit.WebView.<init>(WebView.java:1054) 
at android.webkit.WebView.<init>(WebView.java:1044) 
at android.webkit.WebView.<init>(WebView.java:1035) 
at com.example.MyApplication.getWebView(MyApplication.java:223) 
at com.example.MyApplication.loadUrlInWebView(MyApplication.java:249) 
at com.example.MyApplication.onCreate(MyApplication.java:169) 
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:984) 
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3825) 
... 10 more 

为什么会崩溃,这些正在发生?有没有其他人有这个问题?

注:错误报告的平台均列为其他,所以也许这只是一个仿真器或操作系统的非正式版本发生。

回答

2

这可能与webview DOM存储有关。请参阅WebSettings.setDatabaseEnabled和WebSettings.setDatabasePath。

http://developer.android.com/reference/android/webkit/WebSettings.html#setDatabaseEnabled(boolean) http://developer.android.com/reference/android/webkit/WebSettings.html#setDatabasePath(java.lang.String)

一个常见的抱怨是,DOM存储不工作,这通常是固定的这样的代码:

mWebView.getSettings().setDomStorageEnabled(true); 
mWebView.getSettings().setDatabaseEnabled(true); 
mWebView.getSettings().setDatabasePath("/data/data/packagename/databases/"); 

我从来没有听说过的崩溃问题,这一点,但当你禁用DOM存储以及指定正确的数据库路径时(如上面使用应用程序的包名所示),可能值得研究一下。

这个线程也可能会有所帮助:
Android - Making Webview DomStorage persistant after app closed

+0

这似乎很可能是罪魁祸首。我没有加载任何利用HTML5数据API的HTML,所以我不知道我是否可以完全关闭DOM存储和数据库访问?如果我不需要,我不愿意硬编码数据库路径。 – 2011-12-30 01:15:33