安卓开发,HttpResponse httpResponse = httpClient.execute(new HttpGet(url));语句无法执行的问题。 15
急需解决。写安卓程序,功能是从网上读取一个文本文件并打印出来,但是执行到HttpResponsehttpResponse=httpClient.execute(newHt...
急需解决。写安卓程序,功能是从网上读取一个文本文件并打印出来,但是执行到HttpResponse httpResponse = httpClient.execute(new HttpGet(url));就停住了(由打印调试可得到这个结论),请求热心网友帮助!代码如下:
(由于字数限制,导入的包名没有列出,末尾加/////////的为调试语句)
public class MainActivity extends Activity {
private Button geocoding = null;
private Button reverseGeocoding = null;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
geocoding = (Button)findViewById(R.id.geocoding);
geocoding.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
new Thread(){
public void run(){
Log.d("yinan", "run");/////////
String url = "http://maps.google.com/maps/api/geocode/json?address=SFO&sensor=false";
String responseData = "" ;
Log.d("yinan", "url");/////////
HttpClient httpClient = new DefaultHttpClient();
Log.d("yinan", "DefaultHttpClient");/////////
try {
Log.d("yinan", "#############");/////////
HttpResponse httpResponse = httpClient.execute(new HttpGet(url));//发送一个GET请求
Log.d("yinan", "httpResponse");/////////
HttpEntity entity = httpResponse.getEntity();
Log.d("yinan", "Entity!!!");/////////
BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));
String str;
Log.d("yinan", "OnClickListener");/////////
while((str = br.readLine()) != null){
Log.d("yinan", str);
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}.start();
}
});
}
} 展开
(由于字数限制,导入的包名没有列出,末尾加/////////的为调试语句)
public class MainActivity extends Activity {
private Button geocoding = null;
private Button reverseGeocoding = null;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
geocoding = (Button)findViewById(R.id.geocoding);
geocoding.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
new Thread(){
public void run(){
Log.d("yinan", "run");/////////
String url = "http://maps.google.com/maps/api/geocode/json?address=SFO&sensor=false";
String responseData = "" ;
Log.d("yinan", "url");/////////
HttpClient httpClient = new DefaultHttpClient();
Log.d("yinan", "DefaultHttpClient");/////////
try {
Log.d("yinan", "#############");/////////
HttpResponse httpResponse = httpClient.execute(new HttpGet(url));//发送一个GET请求
Log.d("yinan", "httpResponse");/////////
HttpEntity entity = httpResponse.getEntity();
Log.d("yinan", "Entity!!!");/////////
BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));
String str;
Log.d("yinan", "OnClickListener");/////////
while((str = br.readLine()) != null){
Log.d("yinan", str);
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}.start();
}
});
}
} 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询