【问题标题】:webview turns black and application crasheswebview变黑,应用程序崩溃
【发布时间】:2019-05-31 21:23:27
【问题描述】:

我的 android 应用程序有多个 webviews。运行几分钟后,webview 变黑并导致应用程序崩溃。

这是 webview xml

<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="63dp"
android:visibility="visible" />;

这是在我的 Activity 中初始化 webview 的代码。

mywebPage = (WebView) findViewById(R.id.webView);
mywebPage.getSettings().setJavaScriptEnabled(true);
mywebPage.getSettings().setDomStorageEnabled(true);
mywebPage.addJavascriptInterface(this, "Android");
mywebPage.setFocusable(true);
mywebPage.setFocusableInTouchMode(true);
mywebPage.setWebChromeClient(new WebChromeClient() {
    public boolean onConsoleMessage(ConsoleMessage cm) {
        LogUtil.writeLog(this.getClass(), "WebView " + cm.message() + " -- From line " + cm.lineNumber() + " of " + cm.sourceId());
            return true;
    }
});

提前感谢您的帮助!

【问题讨论】:

    标签: android webview crash android-webview


    【解决方案1】:

    您在XML 中的id 与Activity 中调用的id 不一样。 尝试在activity 中这样定义。 并且作为建议,每当您定义需要以小写开头的内容时。 例如:myWebPageandroid:id="@+id/tvInfo"

    myWebPage = (WebView) findViewById(R.id.Info);
    

    【讨论】:

    • 谢谢。出于安全原因,我不得不重命名几个 ID。我错过了在代码中更新它们。将更新它们以匹配。再次感谢。
    • 我在这里复制+粘贴错误。实际代码是完美的。我们仍然有这个问题。屏幕随机变黑并崩溃。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-13
    • 1970-01-01
    相关资源
    最近更新 更多