大神来帮小弟我看看把
大神来帮我看看把
为什么第二个try的BufferedReader reader=new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
这句和is.close();这句话会出错呢
try{
HttpClient httpclient=new DefaultHttpClient();
HttpPost httppost=new HttpPost("http://110.86.69.250/getAllPeopleBornAfter.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response =httpclient.execute(httppost);
HttpEntity entity=response.getEntity();
InputStream is=entity.getContent();
}catch(Exception e){
Log.e("log_tag", "Error in http connection" + e.toString());
}
try{
BufferedReader reader=new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb=new StringBuilder();
String line =null;
while((line=reader.readLine())!=null){
sb.append(line+"\n");
}
is.close();
result=sb.toString();
}catch(Exception e){
Log.e("log_tag","Error converting result" + e.toString());
}
------解决方案--------------------
将2个try合并成一个,例如
为什么第二个try的BufferedReader reader=new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
这句和is.close();这句话会出错呢
try{
HttpClient httpclient=new DefaultHttpClient();
HttpPost httppost=new HttpPost("http://110.86.69.250/getAllPeopleBornAfter.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response =httpclient.execute(httppost);
HttpEntity entity=response.getEntity();
InputStream is=entity.getContent();
}catch(Exception e){
Log.e("log_tag", "Error in http connection" + e.toString());
}
try{
BufferedReader reader=new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb=new StringBuilder();
String line =null;
while((line=reader.readLine())!=null){
sb.append(line+"\n");
}
is.close();
result=sb.toString();
}catch(Exception e){
Log.e("log_tag","Error converting result" + e.toString());
}
------解决方案--------------------
将2个try合并成一个,例如
- Java code
try{ HttpClient httpclient=new DefaultHttpClient(); HttpPost httppost=new HttpPost("http://110.86.69.250/getAllPeopleBornAfter.php"); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response =httpclient.execute(httppost); HttpEntity entity=response.getEntity(); InputStream is=entity.getContent(); BufferedReader reader=new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8); StringBuilder sb=new StringBuilder(); String line =null; while((line=reader.readLine())!=null){ sb.append(line+"\n"); } is.close(); result=sb.toString(); }catch(Exception e){ Log.e("log_tag", "Error in http connection" + e.toString()); }