CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
Only the original thread that created a view hierarchy can touch its views. 뷰 계층 구조를 만든 원래 스레드 만 해당 뷰를 만질 수 있다.
android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:8551)
at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:1474)
at android.view.View.requestLayout(View.java:24551)
at android.view.View.setFlags(View.java:15275)
at android.view.View.setVisibility(View.java:10898)
at android.app.Dialog.hide(Dialog.java:432)
at ddolcat.com.test.MapsActivity.hideProgressDialog(MapsActivity.java:1626)
at ddolcat.com.test.MapsActivity.access$900(MapsActivity.java:91)
at ddolcat.com.test.MapsActivity$13.run(MapsActivity.java:1553)
at java.lang.Thread.run(Thread.java:919)
2020-06-15 08:28:53.417 27421-27421/ddolcat.com.test E/libprocessgroup: set_timerslack_ns write failed: Operation not permitted
2020-06-15 08:28:53.518 27421-27702/ddolcat.com.test E/UncaughtException: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:8551)
at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:1474)
at android.view.View.requestLayout(View.java:24551)
at android.view.View.setFlags(View.java:15275)
at android.view.View.setVisibility(View.java:10898)
at android.app.Dialog.hide(Dialog.java:432)
at ddolcat.com.test.MapsActivity.hideProgressDialog(MapsActivity.java:1626)
at ddolcat.com.test.MapsActivity.access$900(MapsActivity.java:91)
at ddolcat.com.test.MapsActivity$13.run(MapsActivity.java:1553)
at java.lang.Thread.run(Thread.java:919)
2020-06-15 08:28:53.868 27421-27700/ddolcat.com.test E/FirebaseCrash: Unable to parse Json response string to get message: No value for crashes
2020-06-15 08:28:54.019 27421-27421/ddolcat.com.test E/WindowManager: android.view.WindowLeaked: Activity ddolcat.com.test.MapsActivity has leaked window DecorView@909a771[MapsActivity] that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:625)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:403)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:102)
at android.app.Dialog.show(Dialog.java:416)
at ddolcat.com.test.MapsActivity.showProgressDialog(MapsActivity.java:1620)
at ddolcat.com.test.MapsActivity.setMapMarkerForTradeName(MapsActivity.java:1438)
at ddolcat.com.test.MapsActivity.access$400(MapsActivity.java:91)
at ddolcat.com.test.MapsActivity$3.onItemSelected(MapsActivity.java:424)
at android.widget.AdapterView.fireOnSelected(AdapterView.java:957)
at android.widget.AdapterView.dispatchOnItemSelected(AdapterView.java:946)
at android.widget.AdapterView.access$300(AdapterView.java:55)
at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:910)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7615)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
■오류가 발생한 코드 위치
new Thread(new Runnable() {
@Override
public void run() {
for(int i=0; i<tradeArr.length;i++){
...........................
}
hideProgressDialog(); //오류 발생 코드
}
}).start();
[해결책] runOnUiThread 사용해서 해결하면 된다.
runOnUiThread(new Runnable() {
@Override
public void run() {
hideProgressDialog();
}
}
});