0

ListView의 항목에 대한 추가 정보를 표시하는 대화 상자 팝업을 만들려고합니다. ListView 잘 생성하고 대화 상자의 모든 변수를 잘 초기화하고 있지만 EditText 상자에 관련된 설명을 쓸 때 NullPointerException throw됩니다. 어떤 아이디어?EditText가있는 Android 대화 상자에서 NullPointerException을 throw합니다.

@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(); 
    } 

답변

6

사용

EditText descriptionOutput = (EditText)dialog.findViewById(R.id.dialogText); 

대신

EditText descriptionOutput = (EditText) findViewById(R.id.dialogText); 

대화 레이아웃

에서의 EditText에 액세스 할 수
관련 문제