我正在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