我有一个问题,我想解析Web上的XML文件。现在我的HttpResponce读取的XML文件太多,所以我得到了错误“成为运行时错误”为我的GUI。Android中的HttpResponse
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://chukk.nuzoka.com/name.xml");
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
line = EntityUtils.toString(httpEntity);
} catch (UnsupportedEncodingException e) {
line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
} catch (MalformedURLException e) {
line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
} catch (IOException e) {
line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
}
任何帮助表示赞赏:)
你在一个单独的线程中这样做的权利? – L7ColWinters 2012-02-26 21:46:27
只是一个侧面说明,考虑使用StreamReader而不是EntityUtils.toString,以提高内存使用率。 – yorkw 2012-02-26 22:43:32
@ yorkw你有什么可以支持的吗?我正在使用EntityUtils .. – nhaarman 2012-02-26 23:12:29