Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有EditText的Android对话框引发NullPointerException_Android_Listview_Dialog_Nullpointerexception_Android Edittext - Fatal编程技术网

带有EditText的Android对话框引发NullPointerException

带有EditText的Android对话框引发NullPointerException,android,listview,dialog,nullpointerexception,android-edittext,Android,Listview,Dialog,Nullpointerexception,Android Edittext,我试图弹出一个对话框,显示有关ListView中条目的更多信息。ListView生成良好,对话框的所有变量初始化良好,但当我尝试将相关描述写入EditText框时,会引发NullPointerException。有什么想法吗 @Override protected void onListItemClick(ListView l, View v, int position, long id) { //TODO Add code for action performed on item

我试图弹出一个对话框,显示有关ListView中条目的更多信息。ListView生成良好,对话框的所有变量初始化良好,但当我尝试将相关描述写入EditText框时,会引发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();
  }
使用

而不是

EditText descriptionOutput = (EditText) findViewById(R.id.dialogText);
要从对话框布局访问编辑文本,请使用

而不是

EditText descriptionOutput = (EditText) findViewById(R.id.dialogText);
从对话框布局访问编辑文本的步骤