title: Null pointer exception in android
body: <p>I have the following code for my dialog box, I want to get some text from the alert box, but the below given code throws null pointer exception.</p>
  
  <pre><code>public EditText summarytext;
  public Button done;
  Context mContext = getApplicationContext();
      Dialog dialog = new Dialog(mContext);
      dialog.setContentView(R.layout.summaryalert);
      dialog.setTitle("Other");
  
      done=(ButtonfindViewById(R.id.btn);
      done.setOnClickListener(don);&lt;----Nullpointer Exception
  </code></pre>
  
  <hr>
  
  <hr>
  
  <pre><code>     private View.OnClickListener don=new  View.OnClickListener() {
                   @Override          
  public void onClick(View v) {
                      // TODO Auto-generated method stub
                      if(v==findViewById(R.id.btn)){
                      summarytext=(EditText)findViewById(R.id.summarytext);
                      sumry=summarytext.getText().toString();
                      String display=""+sumry;
                      Toast toast = Toast.makeText(getBaseContext(),
       display, Toast.LENGTH_LONG);
                      toast.show();
                      }
  </code></pre>
  
  <hr>
  
  <hr>
  
  <h2>summary alert</h2>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout
  android:id="@+id/widget31"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:background="#000000"
  android:gravity="center"
  xmlns:android="http://schemas.android.com/apk/res/android"
  &gt;
  &lt;TableRow
  android:id="@+id/widget60"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:gravity="center"
  &gt;
  &lt;TextView
  android:id="@+id/text"
  android:text="Other(provide summary)"
  android:textColor="#ffffff"
  &gt;&lt;/TextView&gt;&lt;/TableRow&gt;
  &lt;TableRow
  android:id="@+id/widget60"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:gravity="center"
  &gt;
  &lt;EditText
  android:id="@+id/summarytext" 
  android:layout_height="wrap_content" 
  android:layout_width="wrap_content" 
  &gt;
  &lt;/EditText&gt;
  &lt;/TableRow&gt;
  &lt;TableRow
  android:id="@+id/widget60"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:gravity="center"
  &gt;
  &lt;Button
  android:id="@+id/btn"
  android:text="Done"
  &gt;&lt;/Button&gt;
  &lt;/TableRow&gt;
  </code></pre>
  
  <h2>    </h2>
  
  <h2>mainlayout</h2>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout
  android:id="@+id/widget31"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="#ffffffff"
  android:orientation="vertical"
  xmlns:android="http://schemas.android.com/apk/res/android"
  &gt;
  &lt;TableLayout
  android:id="@+id/widget58"
  android:layout_width="320px"
  android:layout_height="65px"
  android:orientation="vertical"
  &gt;
  &lt;TableRow
  android:id="@+id/widget60"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:gravity="center"
  &gt;
  &lt;EditText
  android:id="@+id/other" 
  android:layout_height="fill_parent" 
  android:layout_width="fill_parent" 
  android:ems="15"&gt;
  &lt;/EditText&gt;
  &lt;/TableRow&gt;
  &lt;TableRow
  android:id="@+id/widget42"
  android:layout_height="fill_parent"
  android:layout_width="fill_parent"
  android:gravity="center"
  &gt;
  &lt;Button
  android:id="@+id/submit"
  android:layout_width="155px"
  android:layout_height="41px"
  android:text="Done"
  android:layout_x="77px"
  android:layout_y="313px"
  &gt;
  &lt;/Button&gt;
  &lt;/TableRow&gt;&gt;
  &lt;/TableLayout&gt;
  </code></pre>
  
  <h2>    </h2>
  
  <p><strong>Edit</strong></p>
  
  <p><strong>solved..!</strong></p>
  
  <p>include 'dialog'</p>
  
  <blockquote>
    <p>done=(Button)dialog.findViewById(R.id.btn);</p>
  </blockquote>