ArrayAdapter.getCount() NullPointerException
<p>I have following code in my android application:</p>

<pre><code>   protected ArrayList&lt;String&gt; message;

   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.where_to_go);

      whereToGoField = (AutoCompleteTextView)findViewById(R.id.WhereToGoField);

      adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_dropdown_item_1line);
      whereToGoField.addTextChangedListener(whereToGoFieldInputWatcher);
      whereToGoField.setAdapter(adapter);
   }


   TextWatcher whereToGoFieldInputWatcher = new TextWatcher() {
      public void onTextChanged(final CharSequence s, int start, int before, int count) {
         Thread t = new Thread() {
            public void run() {
               Object o = Server.getStreetSuggestions(s.toString());
               if (o!=null) {
                  message = (ArrayList&lt;String&gt;)o;
               }
               messageHandler.sendEmptyMessage(0);
            }
         };
         t.start();
      }

   };

   private Handler messageHandler = new Handler() {
      public void handleMessage(Message msg) {
         adapter.clear();
          for(int i=0; i&lt;message.size(); ++i){
              adapter.add(message.get(i));
          }
          adapter.notifyDataSetChanged();
      }
   };
</code></pre>

<p>Basicaly it gets response from my server and populate this response in autocompletetextview.</p>

<p>But some times I getting following error:</p>

<pre><code>04-25 16:08:42.288: ERROR/AndroidRuntime(6193): FATAL EXCEPTION: main
04-25 16:08:42.288: ERROR/AndroidRuntime(6193): java.lang.NullPointerException
04-25 16:08:42.288: ERROR/AndroidRuntime(6193):     at android.widget.ArrayAdapter.getCount(ArrayAdapter.java:322)
04-25 16:08:42.288: ERROR/AndroidRuntime(6193):     at android.widget.AdapterView.checkFocus(AdapterView.java:720)
04-25 16:08:42.288: ERROR/AndroidRuntime(6193):     at android.widget.AdapterView$AdapterDataSetObserver.onInvalidated(AdapterView.java:844)
04-25 16:08:42.288: ERROR/AndroidRuntime(6193):     at android.database.DataSetObservable.notifyInvalidated(DataSetObservable.java:74)
04-25 16:08:42.288: ERROR/AndroidRuntime(6193):     at android.widget.BaseAdapter.notifyDataSetInvalidated(BaseAdapter.java:85)
04-25 16:08:42.288: ERROR/AndroidRuntime(6193):     at android.widget.ArrayAdapter$ArrayFilter.publishResults(ArrayAdapter.java:500)
04-25 16:08:42.288: ERROR/AndroidRuntime(6193):     at android.widget.Filter$ResultsHandler.handleMessage(Filter.java:313)
04-25 16:08:42.288: ERROR/AndroidRuntime(6193):     at android.os.Handler.dispatchMessage(Handler.java:130)
04-25 16:08:42.288: ERROR/AndroidRuntime(6193):     at android.os.Looper.loop(Looper.java:154)
04-25 16:08:42.288: ERROR/AndroidRuntime(6193):     at android.app.ActivityThread.main(ActivityThread.java:4668)
04-25 16:08:42.288: ERROR/AndroidRuntime(6193):     at java.lang.reflect.Method.invokeNative(Native Method)
04-25 16:08:42.288: ERROR/AndroidRuntime(6193):     at java.lang.reflect.Method.invoke(Method.java:552)
04-25 16:08:42.288: ERROR/AndroidRuntime(6193):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:917)
04-25 16:08:42.288: ERROR/AndroidRuntime(6193):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:674)
04-25 16:08:42.288: ERROR/AndroidRuntime(6193):     at dalvik.system.NativeStart.main(Native Method)
</code></pre>

<p>I can't understand where it came from. </p>

<p>Can you please help me with it?</p>
