LG Eve 電話でアプリケーションをテストしています。Web から何かをダウンロードしようとするアプリケーションがあり、例外がスローされたときに、エラーが発生したことを示す警告ダイアログを起動することになっています。電話に Wi-Fi 信号がない場合、プログラムは builder.create() でクラッシュします (以下のコードを参照)。ただし、wifi 信号があり、例外が何か他のもの (たとえば、URL のタイプミス) によってスローされた場合、ダイアログは想定どおりに起動します。これがなぜであるかについての手がかりはありますか?
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;
}
showDialog を呼び出す AsyncTask のコード:
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);
}
}