【问题标题】:While loop webview.geturl().contains crashes webviewWhile loop webview.geturl().contains 崩溃 webview
【发布时间】:2017-05-19 15:45:37
【问题描述】:

当我的功能完成时,我希望我的 webview 返回仪表板页面,但是我当前的循环使 webview 崩溃。有什么更好的建议,还是我完全错了?

当前代码:

        @Override
        public void onFinish() {
            mWrappedInstance.onFinish();
            while (!mWebView.getUrl().contains("dashboard")) {
                if (mWebView.canGoBack()) {
                    mWebView.goBack();
                }
            }
        }

【问题讨论】:

  • 你有这么多陈述......请告诉哪个陈述做的。
  • 你会有一个例外。哪一个。发布 logcat。
  • 曾经检查过 .getUrl() 是否返回 null?
  • @greenapps 不,我没有检查 geturl 是否返回 null。现在会检查。
  • 你根本没有回答我的问题。

标签: android webview while-loop contains


【解决方案1】:

使用以下方法更正了错误:

while (!mWebView.getUrl().contains("dashboard")) {
            if (mWebView.canGoBack()) {
            mWebView.goBack();
            }else{
                mWebView.goBack();
                break;
            }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-10
    • 1970-01-01
    • 2022-10-05
    • 1970-01-01
    相关资源
    最近更新 更多