title: Android Dialog EditText doesn't give value
body: <p>I'm trying to get the text from a Dialog, but it doesn't work. All the code works except <code>username = txtDialog.getText().toString();</code></p>
  
  <p>I get a NullpointerException</p>
  
  <p>Here is the complete code :</p>
  
  <pre><code>btn_next.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              dialog  = new Dialog(ResActivity.this);
              dialog.setContentView(R.layout.custom);
              dialog.show();
  
              Button declineButton = (Button) dialog.findViewById(R.id.declineButton);
              declineButton.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      // TODO Auto-generated method stub
                      txtDialog = (EditText)findViewById(R.id.textDialog);
                      username = txtDialog.getText().toString();
                      Intent intent = new Intent(getApplicationContext(), EndActivity.class);
                      intent.putExtra(MESSAGE_NAME, username);
                      startActivity(intent);
                      dialog.dismiss();
                  }
              });
  
          }
      });
  </code></pre>
  
  <p>Can someone help ?</p>