title: Android java.lang.NullPointerException at FindViewById in a dialog
body: <p>I saw many similar questions to this but still cannot resolve mine.</p>
  
  <p>Here is the log:</p>
  
  <pre><code>01-26 00:30:49.714: ERROR/AndroidRuntime(616): FATAL EXCEPTION: main
          java.lang.NullPointerException
          at com.app.newItemList.onDialogPositiveClick(newItemList.java:39)
          at com.app.itemDialog$2.onClick(itemDialog.java:39)
          at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
          at android.os.Handler.dispatchMessage(Handler.java:99)
          at android.os.Looper.loop(Looper.java:137)
          at android.app.ActivityThread.main(ActivityThread.java:4745)
          at java.lang.reflect.Method.invokeNative(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:511)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
          at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Here is the relevant Java files:</p>
  
  <pre><code> package com.app;
  
  import android.app.DialogFragment;
  import android.content.DialogInterface;
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.v4.app.FragmentActivity;
  import android.view.View;
  import android.widget.ArrayAdapter;
  import android.widget.EditText;
  import android.widget.ListView;
  
  import java.util.ArrayList;
  
  /**
   * Created with IntelliJ IDEA.
   * User: Aljarhi
   * Date: 1/24/13
   * Time: 10:22 PM
   * To change this template use File | Settings | File Templates.
   */
  
  public class newItemList extends FragmentActivity
          implements itemDialog.NoticeDialogListener{
  
      public void showNoticeDialog() {
          // Create an instance of the dialog fragment and show it
          DialogFragment dialog = new itemDialog();
          dialog.show(getFragmentManager(), "NoticeDialogFragment");
      }
  
      // The dialog fragment receives a reference to this Activity through the
      // Fragment.onAttach() callback, which it uses to call the following methods
      // defined by the NoticeDialogFragment.NoticeDialogListener interface
      @Override
      public void onDialogPositiveClick(DialogInterface dialog, int id) {
          // User touched the dialog's positive button
          EditText et = (EditText) findViewById(R.id.editText1);
          adapter.add(et.getText().toString());
      }
  
      @Override
      public void onDialogNegativeClick(DialogInterface dialog, int id) {
          // User touched the dialog's negative button
          dialog.cancel();
      }
  
      ArrayAdapter&lt;String&gt; adapter;
  
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.new_list);
  
          ListView lvc = (ListView) findViewById(R.id.listView3);
  
          adapter = new ArrayAdapter&lt;String&gt;(this, R.id.textView2, new ArrayList&lt;String&gt;());
          lvc.setAdapter(adapter);
      }
  
      public void addItem(View clickedButton)
      {
          showNoticeDialog();
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>package com.app;
  
  import android.app.Activity;
  import android.app.AlertDialog;
  import android.app.Dialog;
  import android.app.DialogFragment;
  import android.content.DialogInterface;
  import android.os.Bundle;
  import android.view.LayoutInflater;
  import android.widget.EditText;
  
  /**
   * Created with IntelliJ IDEA.
   * User: Aljarhi
   * Date: 1/25/13
   * Time: 3:11 PM
   * To change this template use File | Settings | File Templates.
   */
  public class itemDialog extends DialogFragment
  {
  
      public interface NoticeDialogListener {
          public void onDialogPositiveClick(DialogInterface dialog, int id);
          public void onDialogNegativeClick(DialogInterface dialog, int id);
      }
  
      @Override
      public Dialog onCreateDialog(Bundle savedInstanceState) {
          AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
          // Get the layout inflater
          LayoutInflater inflater = getActivity().getLayoutInflater();
  
          // Inflate and set the layout for the dialog
          // Pass null as the parent view because its going in the dialog layout
          builder.setView(inflater.inflate(R.layout.dialog_item, null))
                  // Add action buttons
                  .setPositiveButton("ok", new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int id) {
                          mListener.onDialogPositiveClick(dialog, id);
                      }
                  })
                  .setNegativeButton("cancel", new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int id) {
                          mListener.onDialogNegativeClick(dialog, id);
                      }
                  });
          return builder.create();
      }
  
      // Use this instance of the interface to deliver action events
      NoticeDialogListener mListener;
  
      // Override the Fragment.onAttach() method to instantiate the NoticeDialogListener
      @Override
      public void onAttach(Activity activity) {
          super.onAttach(activity);
          // Verify that the host activity implements the callback interface
          try {
              // Instantiate the NoticeDialogListener so we can send events to the host
              mListener = (NoticeDialogListener) activity;
          } catch (ClassCastException e) {
              // The activity doesn't implement the interface, throw exception
              throw new ClassCastException(activity.toString()
                      + " must implement NoticeDialogListener");
          }
      }
  }
  </code></pre>
  
  <p>here is the relevant xml files:</p>
  
  <pre><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:orientation="vertical" android:gravity="center_horizontal|top"&gt;
  
      &lt;TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Mezzo List"
              android:id="@+id/textView2" android:layout_gravity="center_horizontal|top"/&gt;
      &lt;ListView
              android:layout_width="wrap_content"
              android:layout_height="263dp"
              android:id="@+id/listView3" android:layout_gravity="center_horizontal|top" android:choiceMode="none"/&gt;
  
      &lt;Button
              android:layout_width="81dp"
              android:layout_height="wrap_content"
              android:text="Add Item"
              android:id="@+id/button4" android:onClick="addItem"/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <hr>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent"&gt;
  
      &lt;TextView
              android:layout_width="wrap_content"
              android:layout_height="25dp"
              android:text="Mezzo List"
              android:id="@+id/textView4" android:layout_gravity="center"/&gt;
      &lt;TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Enter Item Name:"
              android:id="@+id/textView5" android:layout_gravity="center" android:textSize="20dp"/&gt;
      &lt;EditText
              android:layout_width="205dp"
              android:layout_height="wrap_content"
              android:text="New EditText"
              android:id="@+id/editText1" android:layout_gravity="center" android:inputType="text"
              android:hint="Item Name"
              /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>I found the problem to be in the edittext1 id not recognised or as an edittext although it appeared in the list of choices and I selected it form there. I am using intellij Idea 12.0.2. Any help will be appreciated. Thanks in advance.</p>