3

나는이 오류 메시지가지고 있습니다 안드로이드 4.4 (킷 캣)와 지금 내 넥서스 4에 웹보기를 열려고 :java.lang.IllegalStateException 다음 UI 스레드가 아닌 다른 스레드에서 호출보기 방법

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) 

나는 안드로이드 4.4 내 넥서스 업데이트 이후 4

+1

알려주세요. 얼마나 정확하게 웹보기를 여는 중입니까? "Android 4.4로 업데이트 한 이후"라는 의미는 무엇입니까? 보여줄 코드가 있습니까? – EJK

+1

예외는 UI 스레드에서 코드를 실행해야한다는 것을 의미합니다. 당신은이 문제를 해결하기 위해 핸들러 나 runOnUiThread를 사용할 수 있습니다. – yushulx

답변

4

4.4 구글 추가하고 당신을 무엇 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); 
} 
7

에 몇 가지 변화의 단지 웹보기를 마이그레이션 확인 r과 같은 코드? 시도해 볼 수 있습니다

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

      // TODO Your code 
     } 
    }); 
+0

Jerome에게 감사드립니다! =) – Jorgesys