title: EditText.getText Java.lang nullpointer exception
body: <p>I'm having a problem with my android program.
  I have about every thing working what i want, but now im trying to add a password dialog.</p>
  
  <p>I want to show  a Dialog with a EditText(enter password) and two buttons (ok, cancel).
  (working fine till so far)</p>
  
  <p>When clicking on the OK button the password should be saved in mij SendData Class.</p>
  
  <p>But every time I try to get the content of the EditText it gives a Java.lang NullPointerException.</p>
  
  <p>Can some one help me please?</p>
  
  <p>(I don't have a stack trace as i don't know where to find it :(  because i'm testing on android emulator.)</p>
  
  <p>If there any thing else you need, please feel free to ask.</p>
  
  <p>Here is the XML-FILE</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent" &gt;
  
      &lt;requestFocus /&gt;
  
      &lt;EditText
          android:id="@+id/txt_wachtwoord"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentTop="true"
          android:layout_centerHorizontal="true"
          android:inputType="textPassword" &gt;
  
          &lt;requestFocus /&gt;
      &lt;/EditText&gt;
  
      &lt;Button
          android:id="@+id/DialogOK"
          android:layout_width="100dp"
          android:layout_height="wrap_content"
          android:layout_alignRight="@+id/txt_wachtwoord"
          android:layout_below="@+id/txt_wachtwoord"
          android:layout_marginTop="22dp"
          android:text="OK" /&gt;
  
      &lt;Button
          android:id="@+id/Cancel"
          android:layout_width="100dp"
          android:layout_height="wrap_content"
          android:layout_alignBaseline="@+id/DialogOK"
          android:layout_alignBottom="@+id/DialogOK"
          android:layout_toRightOf="@+id/DialogOK"
          android:text="Cancel" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Here is the code:</p>
  
  <pre><code>    package SebApp.Phone.Remote;
  
      import java.net.DatagramSocket;
  
      import android.app.Activity;
      import android.app.Dialog;
      import android.os.Bundle;
      import android.view.View;
      import android.view.View.OnClickListener;
      import android.widget.Button;
      import android.widget.TextView;
      import android.widget.EditText;
      import android.widget.Toast;
      import android.os.Vibrator; 
      import android.app.AlertDialog;
      import android.content.DialogInterface;
  
      public class PhoneRemote extends Activity {
  
      private static final int VIBRATE_TIME = 100;
  
      /** Called when the activity is first created. */
      public Vibrator vibrator = null;
      public sendData sd = new sendData();
  
      @Override
      public void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);    
          setContentView(R.layout.main);
  
          vibrator = (Vibrator)getSystemService(VIBRATOR_SERVICE);      
  
          //button to call the Dialog
          Button ww = (Button) findViewById(R.id.ww);
  
          //listener password button
          ww.setOnClickListener(wwOnClickListener);
  
      }
  
      Button.OnClickListener wwOnClickListener = new Button.OnClickListener() {    
  
          public void onClick(View v) {           
              try{
                  final EditText ww = (EditText) findViewById(R.id.txt_wachtwoord);
                  //set up dialog
                  Dialog dialog = new Dialog(PhoneRemote.this);
                  dialog.setContentView(R.layout.wachtwoord);
                  dialog.setTitle("This is my custom dialog box");
                  dialog.setCancelable(true);
                  //there are a lot of settings, for dialog, cheout!
  
                  //set up button
                  Button button = (Button) dialog.findViewById(R.id.DialogOK);
                  button.setOnClickListener(new OnClickListener() {
                      public void onClick(View v) {                 
                          try{
                              Toast.makeText(v.getContext(),"PWfield contains: " + ww.getText().toString(), Toast.LENGTH_SHORT).show();
                              //finish();
                          }catch(Exception e)
                          {
                              Toast.makeText(v.getContext(),e.toString(), Toast.LENGTH_SHORT).show();
                          }
                      }
                  });           
                  dialog.show();
              }catch(Exception E){
                  Toast.makeText(v.getContext(),E.toString(), Toast.LENGTH_SHORT).show();
              }
  
          }
      };
  }
  </code></pre>