title: Android EditText NullPointerException
body: <p>I need to take data from my <strong>EditText</strong>, which I placed inside dialog.<br>
  When i try to access it I catch NullPointerException.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public class MainActivity extends Activity {
  
      int imgW  ;
      int imgH  ;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
      }
  
      public void OnToolButtonClick(View button)
      {
          switch (button.getId())
          {
          case R.id.btn1:
  
              final Dialog commentDialog = new Dialog(this);
              commentDialog.setContentView(R.layout.reply);
              Button okBtn = (Button) commentDialog.findViewById(R.id.ok);
  
              okBtn.setOnClickListener(new View.OnClickListener() {
  
                  @Override
                  public void onClick(View v) {
  
                      final    EditText     w=  (EditText)findViewById(R.id.dialogW);
                      final    EditText     h=  (EditText) findViewById(R.id.dialogH);
  
                      try {
                          imgW =  Integer.parseInt(w.getText().toString());
                          imgH = Integer.parseInt( h.getText().toString());   
  
                      }
                      catch (NumberFormatException e) {
                          imgH=0;
                          imgW=0;
                      }
  
                      Log.i("Size" ,  " w "+ imgW + " h " + imgH);
                      //  drawing_panel_params
  
                      commentDialog.dismiss();
                  }
              });
              Button cancelBtn = (Button) commentDialog.findViewById(R.id.cancel);
              cancelBtn.setOnClickListener(new View.OnClickListener() {
  
                  @Override
                  public void onClick(View v) {
  
                      commentDialog.dismiss();
                  }
              });
  
              commentDialog.show();
  
              break;
          }
      }
  }
  }
  </code></pre>
  
  <p><strong>Main Layout</strong></p>
  
   <pre class="lang-xml prettyprint-override"><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context="com.example.edittext.MainActivity$PlaceholderFragment" &gt;
  
      &lt;Button
          android:id="@+id/btn1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:clickable="true"
          android:onClick="OnToolButtonClick"
          android:text="@string/Start_dialog" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><strong>Layout for dialog</strong></p>
  
   <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:background="#ffffff"
      android:orientation="vertical" &gt;
  
      &lt;EditText
          android:id="@+id/dialogW"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_gravity="center"
          android:hint="@string/Wight"
          android:lines="3"
          android:textColor="#000000" /&gt;
  
      &lt;EditText
          android:id="@+id/dialogH"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_gravity="center"
          android:hint="@string/Height"
          android:lines="3"
          android:textColor="#000000" /&gt;
  
      &lt;LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="fill_parent" &gt;
  
          &lt;Button
              android:id="@+id/ok"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_weight="1"
              android:text="@android:string/ok" /&gt;
  
          &lt;Button
              android:id="@+id/cancel"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_weight="1"
              android:text="@android:string/cancel" /&gt;
      &lt;/LinearLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>I want to know why is this happening..??</p>