Android - updating a list adapter creates a NullPointException
- by GeekedOut
I have a ListActivity which has an adapter that crashes. Here is the code that crashes the program:
Question q = new Question ();
q.setQuestion( "" );
questions.add(q);
adapter = new ArrayAdapter<Question>(this, R.layout.user_question_list,
R.id.label, questions);
Here is how I create the adapter:
ArrayAdapter<Question> adapter;
ArrayList<Question> questions = new ArrayList <Question>( );
and the list xml is like this:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp" >
</TextView>
and the overall Activity xml is like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/question_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Loading your questions..."
/>
<ListView
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@+id/label"
android:textSize="20px" >
</ListView>
<Button
android:id="@+id/add_question"
android:layout_height="wrap_content"
android:text="Ask a Question"
android:onClick="sendFeedback"
android:layout_width="fill_parent">
</Button>
</LinearLayout>
Any idea why the code where I try to update the adapter results in the NullPointerException?
Thanks!!