2013-03-05 31 views
0

網絡開發人員和不知道有關android。你能幫我解決這個代碼獲取網站回覆的應用程序

例外:android.os.networkmainthreadException上 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());    
     } 

回答

2

你是在UI線程做網絡操作這不允許在android版本> = 3.0所以使用AsyncTask