-1
我有這個應用程序強制關閉此代碼,我做錯了什麼?如何通過HTTP檢索網站?
public void buscaAno(View v){
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://sapires.netne.net/teste.php?formato=json&idade=55");
try {
HttpResponse response = httpclient.execute(httppost);
final String str = EntityUtils.toString(response.getEntity());
TextView tv = (TextView) findViewById(R.id.idade);
tv.setText(str);
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
你在主線程中執行這個代碼?你得到一個android.os.NetworkOnMainThreadException? – 2015-03-18 21:30:50