ListView is null, why? : <p>In a fragment I am trying to set up a list view. In <code>onCreateView()</code> :</p>

<pre><code>mFindFriendsOptionsListView = (ListView) view.findViewById(R.id.find_friends_list_view);
mFindFriendsOptionsAdapter = new FindFriendsOptionsAdapter(mFindFriendOptionIconIds, mFindFriendOptionTitles, mFindFriendOptionDescription);
mFindFriendsOptionsListView.setAdapter(mFindFriendsOptionsAdapter);
</code></pre>

<p>Here is the xml for the list view:</p>

<pre><code>&lt;ListView
        android:id="@+id/find_friends_options_list_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="32dp"
        android:layout_alignParentTop="true"
        android:divider="#999999"
        android:dividerHeight="1dp"/&gt;
</code></pre>

<p>Here is the list element 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"
              xmlns:tools="http://schemas.android.com/tools"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"&gt;

    &lt;LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"&gt;

        &lt;ImageView
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:id="@+id/option_icon_image_view"
            android:layout_marginRight="16dp"
            android:layout_marginEnd="16dp"
            android:layout_marginStart="16dp"
            android:layout_marginLeft="16dp"/&gt;

        &lt;LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_gravity="center_vertical"&gt;

            &lt;TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/option_title_text_view"
                tools:text="Contacts"
                android:textSize="18sp"
                android:layout_marginBottom="6dp"/&gt;

            &lt;TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/option_description_text_view"
                tools:text="Upload contacts to be your friends"
                android:textSize="14sp"/&gt;
        &lt;/LinearLayout&gt;

    &lt;/LinearLayout&gt;

    &lt;ImageView
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:id="@+id/arrow_image_view"
        android:layout_centerVertical="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_marginRight="8dp"
        android:layout_marginEnd="8dp" /&gt;

&lt;/RelativeLayout&gt;
</code></pre>

<p>Here is the stacktrace:</p>

<pre><code>java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
    at com.hb.birthpay.fragment.FindFriendFragment.onCreateView(FindFriendFragment.java:66)
</code></pre>

<p>I have debugged and the field <code>mFindFriendOptionsListView</code> is <code>null</code> even though I set it using <code>findViewById()</code>. Why is the ListView field null and how do I fix this so that I no longer get a <code>java.lang.NullPointerException</code>?</p>
