首页 > 移动平台 > 详细

android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a vi

时间:2015-01-02 09:47:38      阅读:713      评论:0      收藏:0      [点我收藏+]

android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views

这个错误相信大家一定不陌生,特别是刚学习android时,会引起的错误,意思是指在子线程中对UI做了操作,现在写个简单的demo:

public class MainActivity extends Activity {
private TextView textview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textview = (TextView) findViewById(R.id.textview);
new Thread(){
public void run() {
try {
Thread.sleep(1000);
textview.setText("hello");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}.start();
}
}

发现我们是在子线程中对TextView控件中添加内容,导致的错误产生!在此记录下

android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a vi

原文:http://blog.csdn.net/coderinchina/article/details/42321741

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