我有一個問題,我想解析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