异常A WebView method was called on thread 'JavaBridge'. All WebView methods must be called on the same

在创建webview的另外一个地方调用webview加载网页,出现异常:

11-10 13:40:49.793: W/WebView(3684): java.lang.Throwable: A WebView method was called on thread 'JavaBridge'. All WebView methods must be called on the same thread. (Expected Looper Looper (main, tid 1) {52837448} called on Looper (JavaBridge, tid 250) {5289c660}, FYI main Looper is Looper (main, tid 1) {52837448})
11-10 13:40:49.793: W/WebView(3684): 	at android.webkit.WebView.checkThread(WebView.java:2072)
11-10 13:40:49.793: W/WebView(3684): 	at android.webkit.WebView.loadUrl(WebView.java:803)
11-10 13:40:49.793: W/WebView(3684): 	at com.leiting.sdk.channel.leiting.object.BaseObject.reload(BaseObject.java:251)
11-10 13:40:49.793: W/WebView(3684): 	at com.android.org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
11-10 13:40:49.793: W/WebView(3684): 	at com.android.org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:24)
11-10 13:40:49.793: W/WebView(3684): 	at android.os.Handler.dispatchMessage(Handler.java:102)
11-10 13:40:49.793: W/WebView(3684): 	at android.os.Looper.loop(Looper.java:136)
11-10 13:40:49.793: W/WebView(3684): 	at android.os.HandlerThread.run(HandlerThread.java:61)
11-10 13:40:51.377: W/System.err(3684): java.lang.RuntimeException: java.lang.Throwable: A WebView method was called on thread 'JavaBridge'. All WebView methods must be called on the same thread. (Expected Looper Looper (main, tid 1) {52837448} called on Looper (JavaBridge, tid 250) {5289c660}, FYI main Looper is Looper (main, tid 1) {52837448})
11-10 13:40:51.381: W/System.err(3684): 	at android.webkit.WebView.checkThread(WebView.java:2082)
11-10 13:40:51.381: W/System.err(3684): 	at android.webkit.WebView.loadUrl(WebView.java:803)
11-10 13:40:51.381: W/System.err(3684): 	at com.leiting.sdk.channel.leiting.object.BaseObject.reload(BaseObject.java:251)
11-10 13:40:51.381: W/System.err(3684): 	at com.android.org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
11-10 13:40:51.381: W/System.err(3684): 	at com.android.org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:24)
11-10 13:40:51.381: W/System.err(3684): 	at android.os.Handler.dispatchMessage(Handler.java:102)
11-10 13:40:51.385: W/System.err(3684): 	at android.os.Looper.loop(Looper.java:136)
11-10 13:40:51.385: W/System.err(3684): 	at android.os.HandlerThread.run(HandlerThread.java:61)
11-10 13:40:51.385: W/System.err(3684): Caused by: java.lang.Throwable: A WebView method was called on thread 'JavaBridge'. All WebView methods must be called on the same thread. (Expected Looper Looper (main, tid 1) {52837448} called on Looper (JavaBridge, tid 250) {5289c660}, FYI main Looper is Looper (main, tid 1) {52837448})
11-10 13:40:51.385: W/System.err(3684): 	at android.webkit.WebView.checkThread(WebView.java:2072)
11-10 13:40:51.385: W/System.err(3684): 	... 7 more
11-10 13:40:51.393: D/com.leiting.sdk(3684): mWebView WebChromeClientUncaught Error: Error calling method on NPObject.
11-10 13:40:51.393: I/chromium(3684): [INFO:CONSOLE(43)] "Uncaught Error: Error calling method on NPObject.", source: file:///android_asset/html/error.html (43)

分析:根据log日志可以看到是两个使用webview的地方不在同一个线程。

解决方案:

在另外的一个线程中使用webview的方法如下:

                view.post(new Runnable() {
			@Override
			public void run() {
				view.loadUrl(reloadUrl);
			}
		});





你可能感兴趣的:(异常解决)