申请获得网站回复

时间:2013-03-05 15:20:44

标签: java android eclipse

网络开发人员并不了解android。你能帮我解决一下这段代码吗

  

异常:android.os.networkmainthreadException on   client.execute(GET1)

        try
        {

            HttpGet  get1 = new HttpGet ("http://www.google.com/");
            HttpClient client = new DefaultHttpClient();            
            HttpResponse response =   client.execute(get1);
            HttpEntity entity = response.getEntity();
            String responseText = EntityUtils.toString(entity);

        }
        catch(Exception e  )
        {
            urlview.setText( "hi bug"+ e.toString());               
        }

1 个答案:

答案 0 :(得分:2)

你正在UI线程上进行网络操作,在android版本中不允许> = 3.0所以使用AsyncTask