3

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)
Community
  • 1
  • 1
Jack
  • 3,769
  • 6
  • 24
  • 32

4 Answers4

3

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.

hsafarya
  • 1,043
  • 1
  • 10
  • 21
  • 1
    Yeah I am actually, I've got two MapViews in different processes, can't remember why now but there was some issue with using map views on different activities and putting them in different processes helped. – Jack Aug 22 '12 at 16:10
  • Sorry, but for now I don't know how to fix this. Maybe using adview only in one activity but I know that this isn't a solution. – hsafarya Aug 22 '12 at 16:23
1

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.

;)

droidpl
  • 5,872
  • 4
  • 35
  • 47
1

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.

yunas
  • 4,143
  • 1
  • 32
  • 38
1

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)
    }
Dinesh Anuruddha
  • 7,137
  • 6
  • 32
  • 45