机器人的WebView抛出SQLiteException [英] Android WebView throws SQLiteException

查看:195
本文介绍了机器人的WebView抛出SQLiteException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到在我的应用程序,从零星的 SQLiteException 坠毁的报告。我并没有直接与SQLite数据库进行交互的。我一直在跟踪了code下降到的WebView 部件的用法。例外不同原因,但有几个例子如下...

I am getting crash reports from sporadic SQLiteExceptions in my application. I am not directly interacting with SQLite databases at all. I have tracked the code down to the usage of the WebView widget. The exceptions differ in cause, but a couple of examples are as follows...

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)

另一个例子......

Another example...

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

为什么会这些崩溃将发生?任何人都有这个问题?

Why might these crashes be occurring? Has anyone else had this problem?

注意:错误报告的平台分别列为其他,所以也许这只是发生在仿真器或操作系统的非官方版本

Note: The platform in the error reports are each listed as OTHER, so maybe this is only happening in an emulator or unofficial build of the OS.

推荐答案

这可能与web视图DOM存储。见WebSettings.setDatabaseEnabled和WebSettings.setDatabasePath。

This is probably related to the webview DOM storage. See WebSettings.setDatabaseEnabled and WebSettings.setDatabasePath.

<一个href="http://developer.android.com/reference/android/webkit/WebSettings.html#setDatabaseEnabled(boolean" rel="nofollow">http://developer.android.com/reference/android/webkit/WebSettings.html#setDatabaseEnabled(boolean) <一href="http://developer.android.com/reference/android/webkit/WebSettings.html#setDatabasePath(java.lang.String" rel="nofollow">http://developer.android.com/reference/android/webkit/WebSettings.html#setDatabasePath(java.lang.String)

一个常见的​​抱怨是,DOM存储不能正常工作,而且通常是固定的code是这样的:

A common complaint is that the DOM storage does not work, and that is usually fixed with code like this:

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

我从来没有听说过的崩溃问题,这一点,但它可能是值得研究的,当你禁用DOM存储会发生什么,当你指定一个合适的数据库路径(如上图所示,使用你的应用程序的软件包名)。

I never heard of crash problems with this, but it may be worth investigating what happens when you disable DOM storage and when you specify a proper database path (as shown above using your app's packagename).

这线程也可能会有所帮助:
Android的 - 让web视图DomStorage持续性后,应用程序关闭

This thread may also be helpful:
Android - Making Webview DomStorage persistant after app closed

这篇关于机器人的WebView抛出SQLiteException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆