only the original thread that created a view hierarchy can touch its views解决方案

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

此错误是在非UI线程中更新UI所造成的,解决方案如下:(注:在需要更新UI的地方调用new LongTimeTask().execute("此处为任意字符或空均可");)
private class LongTimeTask extends AsyncTask<String, Void, String> {


        @Override
        protected String doInBackground(String... params) {
            return params[0];
        }


        @Override
        protected void onPostExecute(String result) {
            //更新UI的操作,这里面的内容是在UI线程里面执行的
            
        }


    }


你可能感兴趣的:(only the original thread that created a view hierarchy can touch its views解决方案)