title: BaseAdapter crashes on notifyDataSetChanged() call
body: <p>I have created a custom listview and adapter by extending BaseAdapter. Every time I try and call notifyDataSetChanged() on the adapter, the program crashes with a NullPointerException.</p>
  
  <p>This is my code for creating the listview and adapter:</p>
  
  <pre><code>private ArrayList&lt;MessageItem&gt; convList = new ArrayList&lt;MessageItem&gt;();
  
  // setup list view
  ListView list = (ListView)findViewById(R.id.conv_list);
  MessageAdapter dataAdapter = new MessageAdapter(this, convList);
  list.setAdapter(dataAdapter);
  list.setVisibility(View.VISIBLE);
  </code></pre>
  
  <p>I try and update the listview by doing this within an AsyncTask everytime new data is received over the network:</p>
  
  <pre><code>protected class ConversationTask extends AsyncTask&lt;Context, String, String&gt;
      {   
          @Override
          protected String doInBackground(Context... arg0) {
              for (;;) {
                  while (t_recv.messageQueue.isEmpty());
                  publishProgress(t_recv.messageQueue.remove(t_recv.messageQueue.size() - 1));
              }
          }
  
          @Override
          protected void onProgressUpdate(String... i)
          {
              convList.add(new MessageItem("Name", "Msg"));
              dataAdapter.notifyDataSetChanged();
          }
      }
  </code></pre>
  
  <p>A NullPointerException occurs on calling notifyDataSetChanged(). If I remove this call, the listview will only update if I press the back button, or show/hide the keyboard (i'm guessing this somehow triggers an update). So... am I doing something wrong here?</p>
  
  <p>The code for the adapter is below if you need it:</p>
  
  <pre><code>public class MessageAdapter extends BaseAdapter
  {
      private Context context;
  
      private ArrayList&lt;MessageItem&gt; listMessage;
  
      public MessageAdapter(Context context, ArrayList&lt;MessageItem&gt; listMessage) {
          this.context = context;
          this.listMessage = listMessage;
      }
  
      public View getView(int position, View convertView, ViewGroup viewGroup) {
          MessageItem entry = listMessage.get(position);
          if (convertView == null) {
              LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              convertView = inflater.inflate(R.layout.message, null, false);
          }
          TextView tvName = (TextView) convertView.findViewById(R.id.tvName);
          tvName.setText(entry.getName());
  
          TextView tvMsg = (TextView) convertView.findViewById(R.id.tvMsg);
          tvMsg.setText(entry.getMsg());
  
          return convertView;
      }
  
      public int getCount() {
          return listMessage.size();
      }
      public Object getItem(int position) {
          return listMessage.get(position);
      }
      public long getItemId(int position) {
          return position;
      }
  }
  </code></pre>
  
  <p>Each item in the list is a 'MessageItem' as shown below:</p>
  
  <pre><code>public class MessageItem
  {
      private String name;
      private String msg;
  
      public MessageItem(String name, String msg) {
          this.name = name;
          this.msg = msg;
      }
  
      // Getter methods
      public String getName() { return name; }
      public String getMsg() { return msg; }
  }
  </code></pre>
  
  <p>Also, the error is:</p>
  
  <pre><code>04-21 13:56:30.762: ERROR/AndroidRuntime(30024): FATAL EXCEPTION: main
  04-21 13:56:30.762: ERROR/AndroidRuntime(30024): java.lang.NullPointerException
  04-21 13:56:30.762: ERROR/AndroidRuntime(30024):     at com.client.Conversation.appendMessage(Conversation.java:129)
  04-21 13:56:30.762: ERROR/AndroidRuntime(30024):     at com.client.Conversation.access$2(Conversation.java:122)
  04-21 13:56:30.762: ERROR/AndroidRuntime(30024):     at com.client.Conversation$ConversationTask.onProgressUpdate(Conversation.java:170)
  04-21 13:56:30.762: ERROR/AndroidRuntime(30024):     at com.client.Conversation$ConversationTask.onProgressUpdate(Conversation.java:1)
  04-21 13:56:30.762: ERROR/AndroidRuntime(30024):     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:432)
  04-21 13:56:30.762: ERROR/AndroidRuntime(30024):     at android.os.Handler.dispatchMessage(Handler.java:99)
  04-21 13:56:30.762: ERROR/AndroidRuntime(30024):     at android.os.Looper.loop(Looper.java:143)
  04-21 13:56:30.762: ERROR/AndroidRuntime(30024):     at android.app.ActivityThread.main(ActivityThread.java:5068)
  04-21 13:56:30.762: ERROR/AndroidRuntime(30024):     at java.lang.reflect.Method.invokeNative(Native Method)
  04-21 13:56:30.762: ERROR/AndroidRuntime(30024):     at java.lang.reflect.Method.invoke(Method.java:521)
  04-21 13:56:30.762: ERROR/AndroidRuntime(30024):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
  04-21 13:56:30.762: ERROR/AndroidRuntime(30024):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
  04-21 13:56:30.762: ERROR/AndroidRuntime(30024):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Thank you</p>