android应用程序显示线程错误

时间:2013-07-16 16:01:28

标签: java android

我正在尝试为了现在玩Android框架而开发一个非常基本的应用程序。我用3个活动创建了一个简单的应用程序一个将数据插入数据库,一个处理确认消息,最后一个显示到目前为止输入的数据。

我从列表活动(上次执行的)Check picture to see error

收到此错误

我不清楚为什么会发生这种情况,但那是logcat输出。我想要做的就是以下活动:

 HttpResponse response = httpClient.execute(httpPost);
            HttpEntity resEntity = response.getEntity();

            if (resEntity != null) {

                String responseStr = EntityUtils.toString(resEntity).trim();
                Log.v(TAG, "Response: " +  responseStr);
                  TextView responseSimpleText = new TextView(this);
                  responseSimpleText.setText(responseStr.toString());
                // you can add an if statement here and do other actions based on the response

                setContentView(responseSimpleText);
            }else{
                Log.v("ListingAcitivty.java", "Response is Null");
            }

有人可以指出发生了什么吗?我正在使用AsyncTask并使用它成功插入数据。

1 个答案:

答案 0 :(得分:1)

从例外情况来看,您似乎试图从与UI不同的线程更改UI上的某些内容。你不能直接这样做。

  

由于您在线程池中的线程上运行的任务未在UI线程上运行,因此它们无权访问UI对象。

来自:https://developer.android.com/training/multiple-threads/communicate-ui.html

该页面还解释了应该如何处理这种情况。

相关问题