首页 > 其他 > 详细

Only the original thread that created a view hierarchy can touch its views

时间:2015-03-06 10:29:30      阅读:451      评论:0      收藏:0      [点我收藏+]

在调试软件的时候出现如下的错误:

01-05 20:53:36.492: E/ZZShip(2043): android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.

又是一个ThreadException,之前也碰到过。

解决方法:

private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {

  //这里可以做一些,比如关闭加载对话框

}

}

//--------------------------------------------------------------------

try {
new Thread(new Runnable() {
@Override
public void run() {
try {

//打开加载对话框
//与服务器进行通讯

mHandler.post(runnableUI);


} catch (Exception e) {
Log.e(TAG, e.toString());
}
}
}).start();
} catch (Exception e) {
Log.e(TAG, e.toString());
}

 

//--------------------------------------------------------------------

// 构建Runnable对象,在runnable中更新界面
Runnable runnableUI=new Runnable(){
@Override
public void run() {
  //更新UI

  mHandler.sendEmptyMessage(1);//更新完成以后,发送对话框关闭加载对话框
}
};

 

Only the original thread that created a view hierarchy can touch its views

原文:http://www.cnblogs.com/jiduoduo/p/4317424.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!