title: NullPointerException on a listView.setAdapter() method
body: <p>So i got this problem. and i know why. But first code so you will know why too :).</p>
  
  <p>LoveMailsActivity.java:</p>
  
  <pre><code>package com.example.ex;
  
  import android.app.DialogFragment;
  import android.app.FragmentManager;
  import android.os.Bundle;
  import android.support.v7.app.AppCompatActivity;
  import android.view.LayoutInflater;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.AdapterView;
  import android.widget.ArrayAdapter;
  import android.widget.ListView;
  import android.widget.TextView;
  import android.widget.Toast;
  import android.widget.AdapterView.OnItemClickListener;
  
  public class LoveMailsActivity extends AppCompatActivity
  {
  FragmentManager fragmentManager;
  CustomDialogFragment CustomDialogFragment;
  
  //CustomArrayAdapter customArrayAdapter;
  ArrayAdapter&lt;String&gt; arrayAdapter;
  ListView dialogListView;
  
  TextView loveEmailOpeningWordsHeaderTextView;
  
  String[] items = {"Hello","Hello there","Hi","Hi there"};
  
  @Override
  protected void onCreate(Bundle savedInstanceState)
  {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_love_mails);
  
      viewsInitialization();
  
      fragmentManager = getFragmentManager();
      CustomDialogFragment = new CustomDialogFragment();
  
      //customArrayAdapter = new CustomArrayAdapter(LoveMailsActivity.this, items);
      arrayAdapter = new ArrayAdapter&lt;String&gt;(LoveMailsActivity.this, R.layout.list_view_row,R.id.row_text_view_id,items);
      dialogListView.setAdapter(arrayAdapter); // NullPointerExeption
  
      loveEmailOpeningWordsHeaderTextView.setOnClickListener(new View.OnClickListener()
      {
          @Override
          public void onClick(View v) 
          {
              CustomDialogFragment.show(fragmentManager, "Opening words");
          }
      });
  } // End of onCreate() method
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) 
  {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.love_mails, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) 
  {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();
      if (id == R.id.action_settings) 
      {
          return true;
      }
      return super.onOptionsItemSelected(item);
  }
  
  private void viewsInitialization()
  {
      loveEmailOpeningWordsHeaderTextView = (TextView) findViewById(R.id.love_email_opening_words_header_text_view_id);
      dialogListView = (ListView) findViewById(R.id.dialog_list_view_id);
  }
  
  public class CustomDialogFragment extends DialogFragment
  {
      TextView listViewItemTextView;
      ArrayAdapter&lt;String&gt; arrayAdapter;
      ListView dialogListView;
      String[] items = {"Hello","Hello there","Hi","Hi there"};
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState)
      {
          View rootView = inflater.inflate(R.layout.dialog, container,false);
  
          getDialog().setTitle("Choose an option"); // Set dialog title
  
          listViewItemTextView = (TextView) rootView.findViewById(R.id.list_view_item_text_view_id);
          dialogListView = (ListView) rootView.findViewById(R.id.dialog_list_view_id);
  
          getDialog().setTitle("Opening Words"); // Setting dialog title
  
          /*
          CustomArrayAdapter customArrayAdapter = new CustomArrayAdapter(getActivity(), items);
          dialogListView.setAdapter(customArrayAdapter);
          */
          dialogListView.setOnItemClickListener(new OnItemClickListener() 
          {
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view,int position, long id)
              {
                  Toast.makeText(getActivity(), items[position], Toast.LENGTH_SHORT).show();
              }
          });
  
          return rootView;
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>activity_love_mails.xml:</p>
  
  <pre><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.predesignedmails.LoveMailsActivity" &gt;
  
  &lt;TextView
      android:id="@+id/love_email_emai_to_send_to_text_view_id"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="@string/emai_to_send_to_text_view_text"
      android:textSize="16sp"
      android:textStyle="bold"
      android:textColor="@color/opening_words_list_view_header_color"
      /&gt;
  
  &lt;EditText
      android:id="@+id/love_email_email_to_send_to_edit_text_id"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:hint="@string/emai_to_send_to_edit_text_hint"
      android:inputType="textEmailAddress"
      android:textSize="18sp"
      android:textColor="@color/selection_text_color"
      android:layout_below="@id/love_email_emai_to_send_to_text_view_id"
      /&gt;
  
  &lt;TextView
      android:id="@+id/love_email_opening_words_header_text_view_id"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="@string/love_email_opening_words_text_view_text"
      android:textSize="16sp"
      android:textStyle="bold"
      android:textColor="@color/opening_words_list_view_header_color"
      android:layout_below="@id/love_email_email_to_send_to_edit_text_id"
      /&gt;
  
  &lt;TextView
      android:id="@+id/love_email_opening_words_text_view_id"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="@string/initial_text"
      android:textSize="18sp"
      android:textColor="@color/selection_text_color"
      android:layout_below="@id/love_email_opening_words_header_text_view_id"
      /&gt;
  
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Now i get the obvious <code>NullPointerException</code> on the <code>dialogListView.setAdapter(arrayAdapter); // NullPointerExeption</code> line because i dont have any <code>ListView</code> named <code>dialog_list_view_id</code> in the activity_love_mails.xml. I have that kind of <code>ListView</code> in another XML file:</p>
  
  <p>dialog.xml:</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="match_parent"
  android:layout_height="match_parent" &gt;
  
  &lt;ListView 
      android:id="@+id/dialog_list_view_id"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      /&gt;
  
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Now what am i doing wrong? My way of implementing this is obviously wrong and can't figure out what? The <code>CustomDialogFragment</code> class? the <code>ArrayAdapter</code>?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>LogCat:</p>
  
  <pre><code>09-02 19:47:08.208: E/AndroidRuntime(21574): FATAL EXCEPTION: main
  09-02 19:47:08.208: E/AndroidRuntime(21574): Process: com.example.predesignedmails, PID: 21574
  09-02 19:47:08.208: E/AndroidRuntime(21574): java.lang.RuntimeException: Unable to start activity   ComponentInfo{com.example.predesignedmails/com.example.predesignedmails.LoveM    ailsActivity}: java.lang.NullPointerException: Attempt to invoke virtual     method 'void  android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null  object reference
  09-02 19:47:08.208: E/AndroidRuntime(21574):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
  09-02 19:47:08.208: E/AndroidRuntime(21574):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2367)
  09-02 19:47:08.208: E/AndroidRuntime(21574):    at android.app.ActivityThread.access$800(ActivityThread.java:148)
  09-02 19:47:08.208: E/AndroidRuntime(21574):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
  09-02 19:47:08.208: E/AndroidRuntime(21574):    at android.os.Handler.dispatchMessage(Handler.java:102)
  09-02 19:47:08.208: E/AndroidRuntime(21574):    at android.os.Looper.loop(Looper.java:135)
  09-02 19:47:08.208: E/AndroidRuntime(21574):    at android.app.ActivityThread.main(ActivityThread.java:5274)
  09-02 19:47:08.208: E/AndroidRuntime(21574):    at java.lang.reflect.Method.invoke(Native Method)
  09-02 19:47:08.208: E/AndroidRuntime(21574):    at java.lang.reflect.Method.invoke(Method.java:372)
  09-02 19:47:08.208: E/AndroidRuntime(21574):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:90    09-02 19:47:08.208: E/AndroidRuntime(21574):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:704)
  09-02 19:47:08.208: E/AndroidRuntime(21574): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
  09-02 19:47:08.208: E/AndroidRuntime(21574):    at com.example.predesignedmails.LoveMailsActivity.onCreate(LoveMailsActivity.java:45)
  09-02 19:47:08.208: E/AndroidRuntime(21574):    at android.app.Activity.performCreate(Activity.java:5977)
  09-02 19:47:08.208: E/AndroidRuntime(21574):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
  09-02 19:47:08.208: E/AndroidRuntime(21574):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2258)
  09-02 19:47:08.208: E/AndroidRuntime(21574):    ... 10 more
  </code></pre>