Android WebView throws SQLiteException

I get SQLiteException reports from sporadic SQLiteException in my application. I do not directly interact with SQLite databases. I traced the code to using the WebView widget. Exceptions vary for a reason, but a few 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 can these failures occur? Has anyone else had this problem?

Note. The platform in the error reports is indicated as OTHER , therefore, perhaps this only happens in the emulator or in an unofficial OS assembly.

0
source share
1 answer

This is probably due to the web browsing DOM repository. See WebSettings.setDatabaseEnabled and 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)

A common complaint is that the DOM repository is not working, and this is usually fixed with code like this:

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

I have never heard of problems with this failure, but it may be worth exploring what happens when you disable the DOM repository and specify the correct database path (as shown above using your packagename application).

This topic may also be useful:
Android - Permanently saving Webview DomStorage after closing the application

+2
source

All Articles