13

I recieve from google play msg that my app crash, in the msg

java.lang.NullPointerException
at android.webkit.WebViewDatabase.initDatabase(WebViewDatabase.java:234)
at android.webkit.WebViewDatabase.init(WebViewDatabase.java:212)
at android.webkit.WebViewDatabase.access$000(WebViewDatabase.java:40)
at android.webkit.WebViewDatabase$1.run(WebViewDatabase.java:193)

I don't find in google or in stackoverflow similar probloem so I dont know why this crach, but I know that cause by webview.

Thomas Orozco
  • 53,284
  • 11
  • 113
  • 116
idan
  • 1,508
  • 5
  • 29
  • 60
  • can we see the whole stack trace? is there a Caused By? – peshkira Jul 04 '13 at 21:07
  • This is all the report – idan Jul 04 '13 at 21:10
  • Could you post sourcecode? – ArturSkowronski Jul 04 '13 at 21:40
  • the only part that I think that could cause this prob is web.loadData("", "text/html", "utf-8"); the code is too long. and I recently remove this line // web.setPictureListener(new myWebClient()); – idan Jul 04 '13 at 21:53
  • 2
    you need to look at the code on line 234 of WebViewDatabase.java – DigCamara Jul 04 '13 at 22:19
  • When I try to open android.webkit.WebViewDatabase. location from eclipse jar file I recieve this msg " ompiled from WebViewDatabase.java (version 1.5 : 49.0, super bit) public class android.webkit.WebViewDatabase {" and I cant see the code.. – idan Jul 05 '13 at 10:06
  • 1
    I have also received the same exception report (with slightly different line numbers), but I don't explicitly use any web stuff. My app does use ads (admob), so maybe it's something to do with that? – Fish Dec 14 '13 at 19:53
  • I am getting same error. 100% of the error reported by device between 4.0.3-4.04. I don't use webview but admob with google play service. – touchchandra Jan 16 '14 at 16:05
  • I'm getting this issue, and also use admob, 100% also between 4.0.3-4.0.4. – you786 Mar 19 '14 at 05:41

3 Answers3

1

Looks to be the same as this issue here (plus potential workaround):

https://code.google.com/p/android/issues/detail?id=35204

I found the code for WebViewDatabase here (it's not exactly the same version, but there is enough context to get the picture):

http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.1_r1/android/webkit/WebViewDatabase.java#WebViewDatabase.initDatabase%28android.content.Context%29

If you look at the code for initDatabase(), there is a potential NPE on the line that I marked with "****". Note that the following line checks for NULL, so it looks to be a bit dumb:

 private void initDatabase(Context context) {
     try {
         mDatabase = context.openOrCreateDatabase(DATABASE_FILE, 0, null);
     } catch (SQLiteException e) {
         // try again by deleting the old db and create a new one
         if (context.deleteDatabase(DATABASE_FILE)) {
             mDatabase = context.openOrCreateDatabase(DATABASE_FILE, 0,
                     null);
         }
     }

     mDatabase.enableWriteAheadLogging(); ****

     // mDatabase should not be null,
     // the only case is RequestAPI test has problem to create db
     if (mDatabase == null) {
         mInitialized = true;
         notify();
         return;
1800 INFORMATION
  • 131,367
  • 29
  • 160
  • 239
0

Try checking any code that calls android.webkit.WebViewDatabase.initDatabase() Does it have error handling or any problem with opening the database in certain situations?

Do you have error handling / object detection? Can you show a few lines of the code?

Angry 84
  • 2,935
  • 1
  • 25
  • 24
0

I have inspected provided links, android source codes, internal crash analytics and it seems that problem exists only on android 4.0 - 4.0.4. I have tested my suggestion on android 2.3.6, 4.0.3, 4.4.2 and it seems to be correct. So i finished with following workaround for this issue:

package com.android.example;

import android.content.Context;
import android.os.Build;

public class WebViewUtil {

    private static final String WEBVIEW_DATABASE_FILE = "webview.db";

    public static boolean isWebViewCorrupted(Context context) {
        try {
            int currentSdk = Build.VERSION.SDK_INT;
            if (currentSdk == Build.VERSION_CODES.ICE_CREAM_SANDWICH
                    || currentSdk == Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
                try {
                    context.openOrCreateDatabase(WEBVIEW_DATABASE_FILE, 0, null);
                } catch (Throwable t) {
                    // try again by deleting the old db and create a new one
                    context.deleteDatabase(WEBVIEW_DATABASE_FILE);
                    context.openOrCreateDatabase(WEBVIEW_DATABASE_FILE, 0, null);
                }
            }
            return false;
        } catch (Throwable t) {
        }
        return true;
    }
}
Mikalai Parafeniuk
  • 1,328
  • 15
  • 10