title: Android autocomplete null pointer
body: <p>i'm having some trouble with the autocomplete textview in android. I populate the array with contact names but still it gives me this errors. What can be wrong?</p>
  
  <p>Here is the code:</p>
  
  <pre><code>           @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          contactArr = new ArrayList&lt;Contacts&gt;();
          names=new ArrayList&lt;String&gt;();
          t = (TextView) findViewById(R.id.textView1);
          et = (EditText) findViewById(R.id.editText1);
          button = (Button) findViewById(R.id.button1);
          test();
          Log.v("test", names.get(3));
          ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this,
                  R.layout.list_item, names);
  //      autoComplete.setThreshold(2);
          autoComplete.setAdapter(adapter);
          button.setOnClickListener(new OnClickListener() {
  
              public void onClick(View v) {
  
              }
          });
  }
  </code></pre>
  
  <p>Here is how names arraylist is populated:</p>
  
  <pre><code>Cursor phones = getContentResolver().query(
                  ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null,
                  null, null);
          while (phones.moveToNext()) {
              String name = phones
                      .getString(phones
                              .getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
              String phoneNumber = phones
                      .getString(phones
                              .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
              names.add(name); //populated here
  </code></pre>
  
  <p>And finally the errors from logcat:</p>
  
  <pre><code>04-30 19:26:15.389: E/AndroidRuntime(25176): FATAL EXCEPTION: main
  04-30 19:26:15.389: E/AndroidRuntime(25176): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.contact/com.contact.ContactInfoActivity}: java.lang.NullPointerException
  04-30 19:26:15.389: E/AndroidRuntime(25176):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1768)
  04-30 19:26:15.389: E/AndroidRuntime(25176):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
  04-30 19:26:15.389: E/AndroidRuntime(25176):    at android.app.ActivityThread.access$1500(ActivityThread.java:123)
  04-30 19:26:15.389: E/AndroidRuntime(25176):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
  04-30 19:26:15.389: E/AndroidRuntime(25176):    at android.os.Handler.dispatchMessage(Handler.java:99)
  04-30 19:26:15.389: E/AndroidRuntime(25176):    at android.os.Looper.loop(Looper.java:130)
  04-30 19:26:15.389: E/AndroidRuntime(25176):    at android.app.ActivityThread.main(ActivityThread.java:3835)
  04-30 19:26:15.389: E/AndroidRuntime(25176):    at java.lang.reflect.Method.invokeNative(Native Method)
  04-30 19:26:15.389: E/AndroidRuntime(25176):    at java.lang.reflect.Method.invoke(Method.java:507)
  04-30 19:26:15.389: E/AndroidRuntime(25176):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
  04-30 19:26:15.389: E/AndroidRuntime(25176):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
  04-30 19:26:15.389: E/AndroidRuntime(25176):    at dalvik.system.NativeStart.main(Native Method)
  04-30 19:26:15.389: E/AndroidRuntime(25176): Caused by: java.lang.NullPointerException
  04-30 19:26:15.389: E/AndroidRuntime(25176):    at com.contact.ContactInfoActivity.onCreate(ContactInfoActivity.java:41)
  04-30 19:26:15.389: E/AndroidRuntime(25176):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  04-30 19:26:15.389: E/AndroidRuntime(25176):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
  04-30 19:26:15.389: E/AndroidRuntime(25176):    ... 11 more
  </code></pre>
  
  <p>When i remove this line autoComplete.setThreshold(2);
  the new error in log cat is-> </p>
  
  <pre><code>04-30 19:37:10.319: E/AndroidRuntime(25564):    at com.contact.ContactInfoActivity.onCreate(ContactInfoActivity.java:42)
  </code></pre>