为什么android在线程中请求网络数据会报错?去掉线程就好了,有没有大神知道,急!!下面是加 了线程的代码
newThread(){@Overridepublicvoidrun(){try{Stringurl=newTool().url+"getQuestion";HttpRe...
new Thread() {
@Override
public void run() {
try {
String url = new Tool().url+"getQuestion";
HttpResponse httpResponse = null;
HttpPost httpPost = new HttpPost(url);
List<NameValuePair> params = new ArrayList<NameValuePair>();
httpPost.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
httpResponse = new DefaultHttpClient().execute(httpPost);
if (httpResponse.getStatusLine().getStatusCode() == 200)
{
result = EntityUtils.toString(httpResponse.getEntity()).replaceAll("\r", "");
Toast.makeText(getApplicationContext(), result, 1).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}.start(); 展开
@Override
public void run() {
try {
String url = new Tool().url+"getQuestion";
HttpResponse httpResponse = null;
HttpPost httpPost = new HttpPost(url);
List<NameValuePair> params = new ArrayList<NameValuePair>();
httpPost.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
httpResponse = new DefaultHttpClient().execute(httpPost);
if (httpResponse.getStatusLine().getStatusCode() == 200)
{
result = EntityUtils.toString(httpResponse.getEntity()).replaceAll("\r", "");
Toast.makeText(getApplicationContext(), result, 1).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}.start(); 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询