2
我有一個小的Android應用程序,基本上執行http調用來檢索一些網頁信息,並解析它在本地顯示的目的。Android應用程序崩潰3G連接速度慢,但工作正常無線
它在wifi上正常工作。但是,在提交http查詢後,應用程序在3G上隨機崩潰(並非全部,但頻率足夠)。通常我只能重新啓動應用程序,嘗試執行相同的任務,它將按照它的意圖工作。我有點卡住試圖調試這個問題。是否因互聯網連接速度慢導致?數據包丟失?我可以在那裏設置什麼樣的檢查代碼來防止這種情況發生?
一些示例代碼:
HttpClient client = new DefaultHttpClient();
HashMap<String, String[]> hmSearchResults = null;
HttpGet getMethod = new HttpGet(url);
try {
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String resultPage = client.execute(getMethod, responseHandler);
// I am think the error is here if resultPage == null due to
// whatever reason, is there any check I can put around
// client.execute?
hmSearchResults = ParseHtml.getSearchResultText(resultPage, numRequestResults);
} catch (Throwable t) {
Utility.showToast(this,"Request failed: " + t.toString());
}
logcat中的錯誤消息是什麼? – Haphazard 2011-05-21 21:57:04
是的,什麼是錯誤和你在運行這個線程? – Fredrik 2011-05-22 01:19:29
這些任務在AsyncTask的doInBackground()中執行。在手機本身,它只是創建應用程序強制關閉錯誤。我會嘗試在調試模式下重新創建錯誤,並在此處發佈logcat錯誤。 – adjfac 2011-05-22 15:55:09