我正在LG前夕手機上測試我的應用程序。我有一個應用程序試圖從網上下載一些東西,當它拋出一個異常時,它應該啓動一個alertdialog,說有錯誤。當手機沒有wifi信號時,程序在builder.create()中崩潰(見下面的代碼)。然而,當有wifi信號,並且其他異常(例如,url中的輸入錯誤)引發異常時,對話框會按照它應有的方式啓動。任何線索,爲什麼這可能是?應用程序崩潰時做AlertDialog.Builder create()方法 - 安卓
代碼onCreateDialog:
@Override
protected Dialog onCreateDialog(int id){
Dialog d = null;
switch (id){
case DIALOG_DATA_ERROR_ID:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(getResources().getString(R.string.error_data));
builder.setCancelable(false);
builder.setNeutralButton("OK", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface d, int id){
d.cancel();
}
});
d = builder.create();
break;
}
return d;
}
代碼的AsyncTask調用的ShowDialog:
private static class DownloadJSONTask extends AsyncTask<String, Void, String>{
private ProgressDialog dialog;
private Activity parent;
private JSONParserInterface jsonParser;
public DownloadJSONTask(Activity parent, JSONParserInterface jsonParser){
this.parent = parent;
this.jsonParser = jsonParser;
}
protected void onPreExecute(){
dialog = ProgressDialog.show(parent, "Loading", "Please Wait...", true);
}
protected String doInBackground (String... urls){
try {
return HttpHelper.getResponse(urls[0]);
}catch (Exception e){
dialog.cancel();
parent.showDialog(BoomSetListActivity.DIALOG_DATA_ERROR_ID);
}
return null;
}
protected void onPostExecute(String json){
dialog.cancel();
if (jsonParser != null) jsonParser.parse(json);
}
}
你可以顯示異常的logcat/full stacktrace嗎? – 2010-08-18 22:29:48