我已经构建app android使用http客户端从URL获取内容,
String getRequest(String SUrl){
String vResult = "TEST";
//SUrl result of "http://mydomain.com/file.php?var=21"
HttpClient client = new DefaultHttpClient();
HttpGet request;
try{
request=new HttpGet(SUrl);
HttpResponse response = client.execute(request);
vResult=request(response);
}catch(Exception ex){
Log.e("From Server", ex.getMessage());
}
return vResult;
}
public static String request(HttpResponse response){
String result = "";
try{
InputStream in = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder str = new StringBuilder();
String line = null;
while((line = reader.readLine()) != null){
str.append(line + "\n");
}
in.close();
result = str.toString();
}catch(Exception ex){
result = "Error";
}
return result;
}
在android姜饼中,上面的代码工作正常从服务器获取内容,但在果冻bean中代码结果日志就像这样
java.lang.NullPointerException: println needs a message
为什么我在果冻豆中得到null,即使我已经声明了所有变量?
感谢
答案 0 :(得分:1)
试试这个..
catch(Exception ex){
Log.e("From Server", ""+ex.printStackTrace());
}