我创建并显示我的对话在明年方式:AlertDialog在Android 2.1的
showDialog(1); // Logcat say me that mistake is here.
protected Dialog onCreateDialog(int id) {
switch (id) {
case 1:{
Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.SelectLoc)
.setCancelable(true)
.setPositiveButton(R.string.Phone, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
if (mExternalStorageAvailable)
{
PathOpenFile = Environment.getExternalStorageDirectory().getPath();
FileManagerActivity(Settings.Pref.getString("Path_Open", PathOpenFile), REQUEST_LOAD);
}
else
Toast.makeText(Main.this, R.string.CheckSD , Toast.LENGTH_LONG).show();
}
})
.setNegativeButton(R.string.Ftp, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which){
if (Settings.Pref.getBoolean("Ftp_User",false))
{
FtpConnect _FtpConnect = new FtpConnect();
_FtpConnect.Save_Open = FTP_REQUEST_LOAD;
_FtpConnect.execute();
}
else
Toast.makeText(Main.this, R.string.SetPass , Toast.LENGTH_LONG).show();
}
});
AlertDialog dialog = builder.create();
dialog.show();
break;
}
在2.2它非常好,但在2.1它会导致强制关闭 -
“的java.lang .Illegalargumentexeption: 活动#onCreateDialog没有创造 为ID 1" 的对话
为什么会这样?
I fixed see http://stackoverflow.com/questions/6259644/android-java-lang-illegalargumentexception-erron-when-creating-dialog-on-2-1-a/13938677#13938677 – powder366 2012-12-18 17:54:12