Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.IllegalStateException: Calling View methods on another thread than the UI thread

When trying to open a webview on my nexus 4 now with Android 4.4 (Kit kat) I'll getting this error message:

Calling View methods on another thread than the UI thread.; 
java.lang.IllegalStateException: Calling View methods on another thread than the UI thread.
com.android.webview.chromium.WebViewChromium.createThreadException(WebViewChromium.java:268)

Since i update to Android 4.4 my Nexus 4.

like image 379
Jorgesys Avatar asked Nov 28 '13 00:11

Jorgesys


2 Answers

what's your code like? you can try

 runOnUiThread(new Runnable() {
        @Override
        public void run() {

            // TODO Your code
        }
    });
like image 86
Jerome Avatar answered Sep 19 '22 15:09

Jerome


just check migrating web view of 4.4 google added and changed some things in it here

runOnUiThread(new Runnable() {
    @Override
    public void run() {
        // Code for WebView goes here
    }
});


// This code is BAD and will block the UI thread
webView.loadUrl("javascript:fn()");
while(result == null) {
  Thread.sleep(100);
}
like image 43
pavanmvn Avatar answered Sep 17 '22 15:09

pavanmvn