1

私のアプリでは、webview を使用して多くの html ファイルを読み込む必要があります。いくつかのユーザー操作の後、アプリがクラッシュします。LogCat に次のエラーが表示されます: ReferenceTable overflow(max=512)。クラッシュの背後にある理由もわかりました。OS 4.1より前のWebkitのバグでした

このバグを回避する方法がわかりません。任意の回避策をいただければ幸いです。

編集: mWebview を使用して、ローカルの html ファイル (epub ファイルに含まれる) をロードするだけです。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();
}

私のエラーログは次のとおりです。 ここに画像の説明を入力

同じ問題: Android Webview JNI ERROR with loadUrl

4

1 に答える 1

0

私の答えでわかるように: Android Webview JNI ERROR with loadUrlページの読み込みが失敗すると、150 回ごとにアクティビティを破棄しています。あなたの場合、すべてのページの読み込みをカウントする必要があり、特定の量 (150 回など) の後、関数を呼び出して破棄して再起動します。

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);
}

これは回避策であるため、画面がおそらく 0.5 ~ 1 秒間空白/黒くなり、アクティビティが最初から再開されるため、実際の章などを読み続けたい場合は、すべての関連情報を保存する必要があります。
これがうまくいくことを願っています!

于 2013-10-04T03:58:19.893 に答える