0

NET 开发人员,不了解 android。你能帮我修复这个代码吗

异常:client.execute(get1) 上的 android.os.networkmainthreadException

        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());               
        }
4

1 回答 1

2

您正在 UI 线程上进行网络操作,这在 android 版本 >=3.0 中是不允许的,因此请使用AsyncTask

于 2013-03-05T15:22:29.673 回答