-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