0
我試圖做一個彈出對話框,顯示有關ListView中的條目的更多信息。 ListView生成正常,並且對話框的所有變量都初始化正常,但是當我嘗試將相關描述寫入EditText框時,拋出了NullPointerException。有任何想法嗎?使用代替帶有EditText的Android對話框拋出NullPointerException
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
//TODO Add code for action performed on item click here
// i.e. open dialogue showing details
// Custom dialog box
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.view_dialog);
dialog.setTitle("Description: " + savedSubjects[position]);
// set custom dialog components
EditText descriptionOutput = (EditText) findViewById(R.id.dialogText);
String descToWrite = savedDescriptions[position]; // I created this in case calling from the array was the problem. In the trace this variable is correctly set.
descriptionOutput.setText(descToWrite); //the error occurs at this line
// set dismiss button
Button dialogButton = (Button) findViewById(R.id.dialogButton);
//if button is clicked close the dialog
dialogButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});
// display the dialog
dialog.show();
}