解决:Android出现All WebView methods must be called on the same thread.

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sdkdlwk/article/details/80094350
new Thread(){
            public void run() {
                //System.out.println("init-66666666662----");
                view.loadUrl(url);
            }

        }.start();

在新的线程中操作 WebView会报错

04-26 14:52:22.645: E/AndroidRuntime(7635): java.lang.RuntimeException: java.lang.Throwable: A WebView method was called on thread 'Thread-666'. All WebView methods must be called on the same thread. (Expected Looper Looper (main, tid 1) {35b6f8e5} called on null, FYI main Looper is Looper (main, tid 1) {35b6f8e5})

是因为 新版的Android的SDK要求在创建WebView所在的线程中操作它,在其它线程中操作它都会报这样的错误。

解决方法

WebViewActivity.this.runOnUiThread(new Runnable() {//其中 WebViewActivity 是webview所在的Activity    
            public void run() {
                System.out.println("init-66666666662----");
                webview.loadUrl(url);
            }
        });

猜你喜欢

转载自blog.csdn.net/sdkdlwk/article/details/80094350