因此,我试图在从菜单选项打开的警报对话框中制作联系表格。我的表单和 Main.java 中有 3 个 EditText 字段,当按下表单中的“发送”按钮然后我启动电子邮件意图时,我从这些字段中读取,或者至少这就是它应该做的。现在,只要我按下发送按钮,应用程序就会崩溃。现在我已经解决了这个问题,它似乎不是故意的,但是当我从 EditText 字段中读取时它就会发生。当我取出 EditText 阅读部分并将填充信息放在其位置时,代码工作正常,但我需要它与 EditTexts 一起使用。谢谢你。我在菜单中的选项的整个代码:
case R.id.menu_feedback:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.menu_feedback);
LayoutInflater inflater = this.getLayoutInflater();
// Inflate and set the layout for the dialog
// Pass null as the parent view because its going in the dialog layout
builder.setView(inflater.inflate(R.layout.feedback, null));
// Add the buttons
builder.setNegativeButton(R.string.send, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User clicked OK button
final EditText nameField = (EditText) findViewById(R.id.EditTextName);
String name = nameField.getText().toString();
final EditText emailField = (EditText) findViewById(R.id.EditTextEmail);
String email = emailField.getText().toString();
final EditText feedbackField = (EditText) findViewById(R.id.EditTextFeedbackBody);
String feedback = feedbackField.getText().toString();
final CheckBox responseCheckbox = (CheckBox) findViewById(R.id.CheckBoxResponse);
boolean bRequiresResponse = responseCheckbox.isChecked();
/* Create the Intent */
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
/* Fill it with Data */
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, R.string.send_email);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, feedback);
/* Send it off to the Activity-Chooser */
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
dialog.dismiss();
}
});
builder.setPositiveButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
// create alert dialog
AlertDialog alertDialog = builder.create();
// show it
alertDialog.show();
return true;