tImpl $ CalledFromWrongThreadException:只有创建视图层次可以触摸其观点原来的线程 [英] tImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views

查看:106
本文介绍了tImpl $ CalledFromWrongThreadException:只有创建视图层次可以触摸其观点原来的线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

07-17 15:51:16.429: D/visibility(10457): android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
07-17 15:51:21.339: D/visibility(10457): android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
07-17 15:51:32.309: D/visibility(10457): android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
07-17 15:51:40.604: D/visibility(10457): android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.

我的codeS:

My Codes:

try {
                for (int i = 0; i < jArray.length(); i++) {
                    JSONObject json = jArray.getJSONObject(0);
                    String jsona = json.getString("Email");
                    if (jsona == null) {
                        goodrating.setVisibility(View.VISIBLE);
                        badrating.setVisibility(View.VISIBLE);
                    } else {
                        goodrating.setVisibility(View.GONE);
                        badrating.setVisibility(View.GONE);
                    }
                }

            } catch (Exception e) {
                Log.d("visibility", e.toString());
            }

这些code以AsyncTask的DOINBACKGROUND
所以为什么我得到这个错误?

THESE CODES ARE IN ASYNCTASK DOINBACKGROUND so why i'm getting this error?

推荐答案

试着改变你code为:

Try changing you code to:

try {
        for (int i = 0; i < jArray.length(); i++) {
            JSONObject json = jArray.getJSONObject(0);
            String jsona = json.getString("Email");
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    // TODO Auto-generated method stub
                    if (jsona == null) {
                        goodrating.setVisibility(View.VISIBLE);
                        badrating.setVisibility(View.VISIBLE);
                    } else {
                        goodrating.setVisibility(View.GONE);
                        badrating.setVisibility(View.GONE);
                    }
                }
            });
        }

    } catch (Exception e) {
        Log.d("visibility", e.toString());
    }

这篇关于tImpl $ CalledFromWrongThreadException:只有创建视图层次可以触摸其观点原来的线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆