gpt4 book ai didi

android - onCreateDialog 方法中的异常?

转载 作者:搜寻专家 更新时间:2023-11-01 09:12:13 24 4
gpt4 key购买 nike

我得到了

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);

关于android - onCreateDialog 方法中的异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7481462/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com