当我尝试使用Android 4.4 (Kit kat)在我的nexus4上打开一个网页视图时,我得到了这个错误信息:
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)因为我更新到了Android 4.4我的Nexus 4。
发布于 2013-11-28 09:05:04
只需检查4.4Google在here中添加和更改了一些东西的迁移web视图
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);
}发布于 2013-11-28 09:05:29
你的代码是什么样子的?你可以试试
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Your code
}
});发布于 2019-04-17 22:01:49
如果runOnUiThread由于某种原因不可用,您也可以使用以下代码绕过此错误(假设您希望访问某个视图,但不需要显示它):
Handler handler = new Handler(Looper.getMainLooper());
try
{
handler.post(
new Runnable()
{
@Override
public void run()
{
DesiredMethod(); // Where this method runs the code you're needing
}
}
);
} catch (Exception e)
{
e.printStackTrace();
}https://stackoverflow.com/questions/20255920
复制相似问题