我正在制作一个Android应用程序,为此我必须从URL(由一些python脚本输出)获取JSON内容。阅读网页内容,获取异常
我在SO上找到了一个方法,但是我无法让它工作。这是代码:
public String webGet(String URL) throws Exception
{
BufferedReader in = null;
try
{
HttpClient client = new DefaultHttpClient();
client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "android");
HttpGet request = new HttpGet();
request.setHeader("Content-Type", "text/html; charset=utf-8");
request.setURI(new URI(URL));
// Crashes after executing this line
HttpResponse response = client.execute(request);
in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String line = "";
String NL = System.getProperty("line.separator");
while ((line = in.readLine()) != null)
{
sb.append(line + NL);
}
in.close();
String page = sb.toString();
//System.out.println(page);
return page;
}
finally
{
if (in != null)
{
try
{
in.close();
}
catch (IOException e)
{
Log.d("BBB", e.toString());
}
}
}
}
这坠毁行后happends:
HttpResponse response = client.execute(request);
它后来干脆跳到finally
部分和所有我可以从异常消息得到的是某事是null
。这就是它所说的。
任何人都知道问题可能是什么?
截图异常说明:
什么是完整的异常消息? – 2012-07-18 12:47:56
@Vakimshaar添加了错误截图 – w00 2012-07-18 12:55:18
您仍然看不到整个堆栈跟踪 – 2012-07-18 12:58:51