NullPointerException when setting listview adapter (DrawerLayout)
<p>I have a fragment layout which is the drawer and looks like this:</p>

<p><strong>fragment_overview.xml</strong></p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"&gt;

&lt;!-- The main content view --&gt;
&lt;FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffe887" /&gt;

&lt;!-- The navigation drawer --&gt;
&lt;ListView android:id="@+id/left_drawer"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:choiceMode="multipleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp"
    android:background="#111"/&gt;
&lt;/android.support.v4.widget.DrawerLayout&gt;
</code></pre>

<p>And the java class for that fragment:</p>

<p><strong>OverviewFragment.java</strong></p>

<pre><code>@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_overview, container, false);

    mlistOptions = getResources().getStringArray(R.array.list_options);
    mDrawerLayout = (DrawerLayout) getActivity().findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) getActivity().findViewById(R.id.left_drawer);

    // Set the adapter for the list view
    mDrawerList.setAdapter(new ArrayAdapter&lt;String&gt;(getActivity(),
            R.layout.simple_list_item_1, mlistOptions));

    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    return root;
}
</code></pre>

<p>With this code in the resources folder:</p>

<pre><code>&lt;string-array name="list_options"&gt;
    &lt;item&gt;Ship&lt;/item&gt;
    &lt;item&gt;Map&lt;/item&gt;
    &lt;item&gt;Mail&lt;/item&gt;
    &lt;item&gt;Settings&lt;/item&gt;
    &lt;item&gt;Logout&lt;/item&gt;
&lt;/string-array&gt;
</code></pre>

<p>And this as a list item:</p>

<p><strong>simple_list_item_1.xml</strong></p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="15dp"
android:textColor="@android:color/black"
android:textStyle="italic"&gt;
</code></pre>

<p></p>

<p>However when the setAdapter method runs in the java class it generates this error:</p>

<pre><code>java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
</code></pre>

<p>What could have actually gotten wrong in that method call? It is a fragment so we need getActivity as the first parameter, the layout file is just a reference to a simple file and the optionslist is just an arraylist from the resources folder.. what can be null?</p>

<p>Thanks in advance!</p>