1

In my app, I need to use webview to load many html files. After several user operations, the app crashes. LogCat shows the following error: ReferenceTable overflow(max=512). I also found the reason behind the crash. It was a bug in webkit before os 4.1

I don't know how to avoid this bug. Any workaround is appreciated.

Edit: I just use mWebview to load local html file(contained in epub file). mWebView.loadChapter(mSpine.get(mIndex).getHref());

public void loadChapter(String path){
    //loadUrl(resourceUri.toString());

    Object localObject = "";
    try{
        InputStream is = this.getmBook().fetchFromZip(path);
        localObject = fromStream(is);

        is.close();
    }catch(Exception e){
        e.printStackTrace();
    }

    String str1 = "file:///" + path;
    this.clearCache(true);
    loadDataWithBaseURL(str1, (String)localObject, "text/html", "utf-8", null);
}

public String fromStream(InputStream in) throws Exception
{
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    StringBuilder out = new StringBuilder();
    String line;
    while ((line = reader.readLine()) != null) {
        out.append(line);
    }
    return out.toString();
}

My error log as follows: enter image description here

The same problem: Android Webview JNI ERROR with loadUrl

Community
  • 1
  • 1
Xianfeng.Cai
  • 309
  • 1
  • 7
  • 21

1 Answers1

0

As you can see in my answer: Android Webview JNI ERROR with loadUrl I am destroying the Activity every 150 times when a page load fails. In your case you would need to count every page load and after a specific amount (like 150 times) you destroy and restart it by calling the function:

public void KillThisThenStartNewOne(){
  Intent intent = new Intent(this.getApplicationContext(), MainActivity.class);
  intent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);  
  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  this.getApplicationContext().startActivity(intent);
  //for restarting the Activity
  android.os.Process.killProcess(android.os.Process.myPid());
  System.exit(0);
}

As this is a workaround the result will be that the screen will be blank/black for maybe 0.5 to 1 second and your Activity is restarted from the beginning, so you should save all relevant information if you want to continue reading the actual chapter etc.
I hope that this will work for you!

Community
  • 1
  • 1
Micky
  • 499
  • 6
  • 12