솜은 코튼

[error] CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. 본문

Android/오류사항

[error] CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.

솜.코 2021. 4. 16. 11:35

 

 

 

 

 

[오류 사항]

Installation did not succeed. The application could not be installed: INSTALL_FAILED_CONFLICTING_PROVIDER Installation failed due to: 'null'CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.

 

[오류 원인]

설치되어 있는 앱이 있다. 즉 AndroidManifest.xml에 다른 패키지명이 기입되어 있거나, 스키마 명의 대한 오류AsyncTask 메인 쓰레드에서만 UI를 변경할 수 있음.

 

네트워크 통신 혹은 UI값을 바꾸는 것 중 하나만 실행해야 한다.

 

[해결 방법]

1. runOnUiThread

runOnUiThread(new Runnable(){
    @Override
    public void run() {
        // UI 변경 작업
    }
});

2. Handler

Handler handler = new Handler(){
public void handleMessage(Messaage msg){
    // UI 변경 작업 
    }
}
Message msg = handler.obtainMessage();
handler.sendMessage(msg);

 

하지만, 위와 같은 방법으로 적용하여도 동일한 에러가 발생하는 경우가 있다.

만약 ProgressDialog로 인해 오류가 발생하였다면

dismiss() 처리를 hide() 처리로 해준 것은 아닌지 확인해 보자..