我得到了

09-20 12:42:26.697: ERROR/AndroidRuntime(721): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dashboardnew/com.dashboardnew.GmailFetchActivity}: java.lang.IllegalArgumentException: Activity#onCreateDialog did not create a dialog for id 1

2.1和更低版本中的异常。
@Override
protected Dialog onCreateDialog(int id) {

    LayoutInflater factory = LayoutInflater.from(this);

final View textEntryView = factory.inflate(R.layout.alertdialog_gmail, null);

AlertDialog.Builder alert = new AlertDialog.Builder(this);

alert.setTitle("Gmail login");
alert.setMessage("Enter your username and password");
// Set an EditText view to get user input
alert.setView(textEntryView);

final EditText username = (EditText) textEntryView.findViewById(R.id.edit_username);
final EditText password = (EditText) textEntryView.findViewById(R.id.edit_password);

alert.setPositiveButton("Login", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {

    String user=username.getText().toString();
    String pass=password.getText().toString();

    new FetchGmail().execute(user+"@gmail.com",pass);
    progressDialog2.show();


}
});

alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
  public void onClick(DialogInterface dialog, int whichButton) {
    // Canceled.
  }
});

alert.show();


    // TODO Auto-generated method stub
    return super.onCreateDialog(id);


}

最佳答案

试试这个:

return alert.create();

而不是:
alert.show();

// TODO Auto-generated method stub
return super.onCreateDialog(id);

07-26 00:57