android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a vi
2015-01-01 20:42
507 查看
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时,会引起的错误,意思是指在子线程中对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
- android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a vi
- android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a vi
- android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a vi
- android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a vi
- android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
- android ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hi
- android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a v
- android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view
- ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy
- android.view.viewroot$calledfromwrongthreadexception: only the original thread that created a view h
- 16-07-24 android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that
- android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original
- android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original
- Android异常:android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original
- 子线程中处理UI,抛异常 android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original
- Android异常:android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original
- android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original
- calledfromwrongthreadexception only the original that created a view hierarchy can touch its views
- CalledFromWrongThreadException: Only the original thread that created a view