我在主函数里写了一个方法来获取http请求的数据。。一直无法运行。
下面这段程序我在调试的时候连thread方法都没法进去。。
void getNametext(final String string) {
new Thread(new Runnable() {
@Override
public void run() {
try {
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(string);
HttpResponse httpResponse = httpClient.execute(httpGet);
if (httpResponse.getStatusLine().getStatusCode() == 200) {
System.out.print("-------------"+httpResponse.getStatusLine().getStatusCode());
HttpEntity entity = httpResponse.getEntity();
String response = EntityUtils.toString(entity, "utf-8");
Gson gson = new Gson();
ArrayList<test> arrayList = gson.fromJson(response, new TypeToken<ArrayList<test>>() {
}.getType());
for (test one :
arrayList) {
Log.d("out",one.toString());
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
这个方法在主函数里面被调用、
getNametext("http://localhost/get_data.json");
链接里面的数据也没有错误,是写在本地的一个JSON数据
测试时候用的是真机。。实在找不出是哪里错误。。求指教~~谢谢
你线程都没有启动,怎么操作?