Code
public void changeTextView(String ttext){
textView.setText(text);
}
Error
android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
원인은 사용자 인터페이스와 관련된 모든 동작은 onCreate () 및 이벤트 처리가 실행되는 주 스레드 또는 UI 스레드에서 수행되어야 하는데, 다른 스레드에서 동작할 때 이런 에러가 발생합니다. runOnUiThread를 사용하거나 Handlers를 사용해서 해결이 가능합니다.
public void changeTextView(String ttext){ runOnUiThread(new Runnable() { public void run() { textView.setText(text); } }); }
Reference
https://stackoverflow.com/questions/5161951/android-only-the-original-thread-that-created-a-view-hierarchy-can-touch-its-vi
HAHWULSecurity engineer, Gopher and H4cker! |
0 개의 댓글:
Post a Comment