Populating spinner from a List
<p>I'm having some difficulties populating a <code>Spinner</code> with a <code>List</code> type.</p>

<p>Aim: When a <code>Button</code> is pressed on the main menu, it executes the task GetTownsTask which populates a <code>Spinner</code> on the new screen, but it breaks when setting the <code>Adapter</code>.</p>

<p><strong>MainActivity.java</strong></p>

<pre><code>private class GetTownsTask extends AsyncTask&lt;Void, Void, List&lt;String&gt;&gt; {
    @Override
    protected List&lt;String&gt; doInBackground(Void... p)  {

        // api calls
        List&lt;String&gt; towns = new ArrayList&lt;String&gt;();
        // populate towns
        return towns;
    }

    @Override
    protected void onPostExecute(List&lt;String&gt; townList) {

        Spinner spinner = (Spinner) findViewById(R.id.spinner);
        ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(
                MainActivity.this, 
                android.R.layout.simple_spinner_dropdown_item, 
                townList.toArray( new String[0] ));
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);    // line 124, breaks here
    }
}
</code></pre>

<p><strong>Crash Log</strong></p>

<pre><code>FATAL EXCEPTION: main, 
java.lang.NullPointerException,
at com.project.MainActivity$TestTask.onPostExecute(MainActivity.java:124)
</code></pre>

<p><strong>Spinner screen</strong></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:background="#787878"&gt;

    &lt;Spinner
        android:id="@+id/spinner"
        android:layout_width="200dip"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/townTextView"
        android:layout_below="@+id/townTextView"
        android:layout_marginTop="10dp" /&gt;

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