为什么每次alertdialog都会使我的应用程序崩溃



问题是alert对话框根本不工作,每次都会崩溃

我在youtube上查看了每一行,但对此无能为力

这是代码:

public void showupdatedialogue(String id , String name){
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
LayoutInflater inflater = getLayoutInflater();
View dialog = inflater.inflate(R.layout.update,null);
builder.setView(dialog);
EditText naame = findViewById(R.id.name);
EditText rollno = findViewById(R.id.roll);
EditText cla = findViewById(R.id.clas);
EditText date = findViewById(R.id.dob);
EditText teacher = findViewById(R.id.teacher);
Button up = findViewById(R.id.update);
builder.setTitle("Updating" + " " + name + " " + "record");
builder.show();
up.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String n = naame.getText().toString();
String r = rollno.getText().toString();
String c = cla.getText().toString();
String d = date.getText().toString();
String t = teacher.getText().toString();
updatestudents(id,n,r,d,c,t);
Toast.makeText(MainActivity.this,"record updated",Toast.LENGTH_LONG).show();
}
});

}```

在findViewById((中,您应该添加对话框。findViewById

public void showupdatedialogue(String id , String name){
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
LayoutInflater inflater = getLayoutInflater();
View dialog = inflater.inflate(R.layout.update,null);
builder.setView(dialog);
EditText naame = dialog.findViewById(R.id.name);
EditText rollno = dialog.findViewById(R.id.roll);
EditText cla = dialog.findViewById(R.id.clas);
EditText date = dialog.findViewById(R.id.dob);
EditText teacher = dialog.findViewById(R.id.teacher);
Button up = dialog.findViewById(R.id.update);
builder.setTitle("Updating" + " " + name + " " + "record");
builder.show();
up.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String n = naame.getText().toString();
String r = rollno.getText().toString();
String c = cla.getText().toString();
String d = date.getText().toString();
String t = teacher.getText().toString();
updatestudents(id,n,r,d,c,t);
Toast.makeText(MainActivity.this,"record updated",Toast.LENGTH_LONG).show();
}
});

}

最新更新