Android WebView throws SQLiteException - android

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.

This is probably related to the webview DOM storage. 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 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/");
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).
This thread may also be helpful:
Android - Making Webview DomStorage persistant after app closed

Related

Android SQLite database is locked

I have a bound service running multiple threads that read and write to an SQLite database. I create an instance of my database helper and get a connection to the database in the onCreate of my service, which should execute on the main thread. As it's a bound service there should only ever be one instance of the service in memory. However i still get
exceptions occasionally when the service tries to open the database or when one of the threads tries to execute a statement.
Service code:
#Override
public void onCreate() {
super.onCreate();
MyDatabaseHelper helper = new MyDatabaseHelper(this);
database = helper.getWritableDatabase();
}
Exceptions:
java.lang.RuntimeException: Unable to create service uk.co.example.service.MyService:
android.database.sqlite.SQLiteException: unable to open database file
at android.app.ActivityThread.handleCreateService(ActivityThread.java:1959)
at android.app.ActivityThread.access$2500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:989)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3691)
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:847)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.database.sqlite.SQLiteException: unable to open database file
at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1960)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:887)
at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:965)
at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:958)
at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:585)
at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:118)
at uk.co.example.service.MyService.onCreate(MyService.java:69)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:1949)
... 10 more
android.database.sqlite.SQLiteException: error code 5: database is locked
at android.database.sqlite.SQLiteStatement.native_execute(Native Method)
at android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:61)
at uk.co.example.a.a.a.a(MyTable.java:147)
at uk.co.example.service.b.a.m.run(MySaveTask.java:84)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
at java.lang.Thread.run(Thread.java:1019)
Any ideas what could be causing this?
Thanks
David
Sqlite now supports a new journal mode called Writing-Ahead Logging, which is suitable for concurrent access to sqlite. you may want to take a look at http://www.sqlite.org/wal.html.

Some Android devices report that the table (of a SQLite database) does not exist

I have written an Android application that uses SQLite database which is saved in assets folder.
This database has 4 tables: "table1", "table2" and "table3" and "android_metadata" . The application works fine on most devices, but some crashes have been reported. So I used acra (Application Crash Report for Android, http://code.google.com/p/acra/ ) to collect the log.
I am sure that the database has "table2" table, however the log says there is no such table. I really wonder why it works fine on some devices, but crashes on some others ?
The model of phone is Samsung GT-I9001GT, Android 2.3.3 . Some HTC desire HD had this problem too.
Please help me resolve it. Thanks.
(The database file size is 33KB)
Log
java.lang.RuntimeException: Unable to start activity ComponentInfo{english.idiom/english.idiom.Category2Activity}: android.database.sqlite.SQLiteException: no such table: table2: , while compiling: SELECT subject,table2_id FROM table2 WHERE table1_id=8
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3687)
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:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.database.sqlite.SQLiteException: no such table: table2: , while compiling: SELECT subject,table2_id FROM table2 WHERE table1_id=8
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.SQLiteQuery.<init>(SQLiteQuery.java:49)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1356)
at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1324)
at english.idiom.Category2Activity.getContents(Category2Activity.java:176)
at english.idiom.Category2Activity.Initialize(Category2Activity.java:138)
at english.idiom.Category2Activity.onCreate(Category2Activity.java:70)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
... 11 more
android.database.sqlite.SQLiteException: no such table: table2: , while compiling: SELECT subject,table2_id FROM table2 WHERE table1_id=8
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.SQLiteQuery.<init>(SQLiteQuery.java:49)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1356)
at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1324)
at english.idiom.Category2Activity.getContents(Category2Activity.java:176)
at english.idiom.Category2Activity.Initialize(Category2Activity.java:138)
at english.idiom.Category2Activity.onCreate(Category2Activity.java:70)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3687)
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:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
You really have to check the devices you're willing to support. See
/data/
and check if you have the corresponding table. I've been there, and some devices really differ in terms of package naming, etc.
You can use an app something like, aSQLiteManager to browse schemas.
Other useful sources:
Debugging sqlite database on the device
Android: Where are database files stored?
My question is: do you have other SQL errors in ACRA logs? Particularly, about database corruption?
In my question: Better SQLite corruption detection I presented the quick analysis of SQLite behavior when DB file was randomly modified. When "SELECT *" was failing, sometimes SQLite claimed that it was because the table didn't exist. When I loaded the modified DB file into editor, all tables were missing - so, random modification of the DB file may actually erase all your tables.

Android OutOfMemoryError Crash in startManagingCursor

I am getting a crash report back that says OutOfMemoryError in my call to startManagingCursor. Here is the returned stack trace:
java.lang.OutOfMemoryError
at java.util.ArrayList.add(ArrayList.java:123)
at android.app.Activity.startManagingCursor(Activity.java:1652)
at com.bubblewaretechnology.pianounlockscreen.LockDetecter.onResume(LockDetecter.java:633)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
at android.app.ActivityThread.performNewIntents(ActivityThread.java:1789)
at android.app.ActivityThread.handleNewIntent(ActivityThread.java:1795)
at android.app.ActivityThread.access$2300(ActivityThread.java:124)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1015)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3806)
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)
I am very careful to close my cursors, SQLiteDatabase and SQLiteOpenHelper. Here is a short code segment that the crash refers to:
Cursor callCursor = lockLib.getCallState();
startManagingCursor(callCursor);
....
callCursor.close();
Pretty stumped on how to go about troubleshooting this problem. I know startManagingCursor is depreciated but I am not targeting HONEYCOMB or later, so I cant switch to CursorLoader. Does anyone have any suggestions on how to proceed?
I know it's lame to answer your own question but you can remove startManagingCursor, Reference Link, as long as you are managing the lifecycle of your cursor appropriately.

Android force-close on Google maps: java.lang.NoSuchFieldException: loading_tile_android

One of my Android users is getting a force-close when launching Google Map (MapActivity class) inside my application. He gets a MissingResourceException. He's the only one complaining so far, and he is using Vanilla Tazz phone. The Google maps application itself works well on his device. It looks like it's something specific to Vanilla Tazz. I tried to find a fix online but have not been successful. Here's the Android error log:
java.lang.ExceptionInInitializerError
at ...
at android.view.View.performClick(View.java:2449)
at android.view.View$PerformClick.run(View.java:9027)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ExceptionInInitializerError
at com.google.android.maps.MapActivity.<clinit>(MapActivity.java:295)
... 14 more
Caused by: java.util.MissingResourceException: Could not find required resource
com.android.internal.R$drawable.loading_tile_android (java.lang.NoSuchFieldException: loading_tile_android)
at com.google.android.maps.InternalR.getField(InternalR.java:65)
at com.google.android.maps.InternalR.get(InternalR.java:39)
at com.google.android.maps.InternalR.access$000(InternalR.java:28)
at com.google.android.maps.InternalR$drawable.get(InternalR.java:112)
at com.google.android.maps.InternalR$drawable.<clinit>(InternalR.java:119)
... 15 more
I would appreciate if anyone can suggest anything to fix this.
Not sure you'll find a fix for this: it sounds like the ROM was built without that resource as part of the OS image. They'll probably need a new ROM to get around that.

SQLite Exception in android

hi my application contains SQLite .My application some time getting the following error
java.lang.RuntimeException: Unable to destroy activity {com.fitzsoftware.grocessaryList/com.fitzsoftware.grocessaryList.GrocessaryList}: android.database.sqlite.SQLiteException: unable to close due to unfinalised statements
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3655)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3673)
at android.app.ActivityThread.access$2900(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.database.sqlite.SQLiteException: unable to close due to unfinalised statements
at android.database.sqlite.SQLiteDatabase.dbclose(Native Method)
at android.database.sqlite.SQLiteDatabase.onAllReferencesReleased(SQLiteDatabase.java:320)
at android.database.sqlite.SQLiteDatabase.close(SQLiteDatabase.java:881)
at com.fitzsoftware.grocessaryList.GrocessaryList.onDestroy(GrocessaryList.java:103)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3642)
I am closing the db in Destroy() using DataClass.dh.db.close();
Why this Error occured.Give me the solutions for this.Thanks in advance.
I'm late to the party, but I just saw this. In my case, I had created a Cursor object from a database query, then accidentally closed the database before I closed the cursor. Check whether this is what's happening.
As well Gareth Lloyd's answer, from what I've read of other threads, another cause of this exception is not closing Cursor objects, i.e. attempting to close your SQLiteDatabase instance before closing Cursor objects that have been obtained from querying your SQLiteDatabase instance.

Categories

Resources