搞了一些時間,筆記一下= ='原來是現在新版的sdk不能在主線程運行httpclient
方式1.開新線程
方式1.開新線程
new
Thread(){
@Override
public
void
run()
{
HttpClient httpClient =
new
DefaultHttpClient();
try
{
HttpResponse response = httpClient.execute(httpGet);
}
catch
(Exception e)
{
System.out.println(
"<-------Exception------->"
);
e.printStackTrace();
}
}
}.start();
方式2.
在oncreate()加入
StrictMode.ThreadPolicy policy=new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
StrictMode.setThreadPolicy(policy);
沒有留言:
張貼留言