Jack
Jack

Reputation: 3799

Webview SQLiteException: database is locked

I'm getting an SQLiteException saying the database is locked coming from a webview. I'm not actually using any webviews in my application but I believe its related to admob based on this other stack overflow question which is unanswered.

I am using SQLite in for my own stuff but this shouldn't be causing it should it? I can't seem to replicate it either so I'm not sure how to fix it. Any ideas?

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 android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1916)
at android.webkit.WebViewDatabase.flushCacheStat(WebViewDatabase.java:874)
at android.webkit.CacheManager.trimCacheIfNeeded(CacheManager.java:566)
at android.webkit.WebViewWorker.handleMessage(WebViewWorker.java:193)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.os.HandlerThread.run(HandlerThread.java:60)

Upvotes: 3

Views: 1109

Answers (4)

hsafarya
hsafarya

Reputation: 1053

Do you use multiple processes ? I mean is your activities started in different processes ? If yes , it may cause the problem, because webview using singleton for db management.

Upvotes: 3

Anu
Anu

Reputation: 7177

This happens when multiple threads going to update the data base at the same time .You can avoid this by adding syncronized block in to your code.

synchronized (this) {
        //update your database (one thread at time)
    }

Upvotes: 1

yunas
yunas

Reputation: 4163

Summary : More than 1 connection

Description: You need to make the database connection a singleton instance (shared instance). What I can think of is; this type of errors mostly appear when you have more than 2 database connections opened(even to the same sqlite db). So make sure you have only 1 connection active and the easiest way of doing it is to make ur database instance singleton and shared in the whole app and in that way(shared) you will always have only one connection that will link you to the database.

Upvotes: 1

droidpl
droidpl

Reputation: 5892

Try to modify the StrictMode to see more information about the error. It could be related to a Internet Access on the Main Thread, concurrency problems, a lot of issues, so try posting your manifest to have a look and advice you because this stackTrace doesn't give so much info. And remember to modify the StrictMode and post the messages.

;)

Upvotes: 1

Related Questions