title: Android - AutoCompleteTextView onClick gives an error
body: <p><strong>Solution</strong>
  If you want an onClickListener for your AutoCompleteTextView, do NOT do it in the XML, instead, do it in your Java File. See my answer below. </p>
  
  <p><strong>Original Question</strong></p>
  
  <p>Sorry if I'm missing out on something simple, but I've worked on this for the past 2 hours but I'm stuck. </p>
  
  <p>In my activity, I have 4 AutoCompleteTextViews which are populated by an ArrayList, the values of which come from a database query. Everything works fine until I add an <code>android:onClick</code> property on any of the four AutoCompleteTextViews. I have no idea what's going on, cleaning the project did not save me.</p>
  
  <p>Here are related code:</p>
  
  <p>The global variables I used for the AutoCompleteTextViews:</p>
  
  <pre><code>private ArrayList&lt;String&gt; brands = new ArrayList&lt;String&gt;();
  private ArrayList&lt;String&gt; items = new ArrayList&lt;String&gt;();
  private ArrayList&lt;String&gt; parts = new ArrayList&lt;String&gt;();
  private ArrayList&lt;String&gt; barcodes = new ArrayList&lt;String&gt;();
  
  private AutoCompleteTextView brandACTV;
  private AutoCompleteTextView itemACTV;
  private AutoCompleteTextView partACTV;
  private AutoCompleteTextView barcodeACTV;
  
  private ArrayAdapter&lt;String&gt; adapter;
  </code></pre>
  
  <p>My <code>onCreate()</code> function, pretty standard, I set my layout and initialize my AutoCompleteTextViews</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_search_page);
  
      TextView customerName = (TextView) findViewById(R.id.customerName);
      customerName.setText(getIntent().getStringExtra("customer"));
  
      brandACTV = (AutoCompleteTextView) findViewById(R.id.actvBrand);
      itemACTV = (AutoCompleteTextView) findViewById(R.id.actvItemName);
      partACTV = (AutoCompleteTextView) findViewById(R.id.actvPart);
      barcodeACTV = (AutoCompleteTextView) findViewById(R.id.actvBarcode);
  
  
      new InitTask().execute("");
  }
  </code></pre>
  
  <p>What happens in when I execute the <code>InitTask</code> thread is that I display a spinning progress bar while I do database queries to initialize my ArrayList arrays for my AutoCompleteTextViews.</p>
  
  <p>In the InitTask's <code>doInBackground</code> method, I call my <code>getArrays()</code> function:</p>
  
  <pre><code>public void getArrays(){
              //itemListDB is an object of my DatabaseAdapter class
      itemListDB.open();
  
      brands = itemListDB.getAllBrands();
      items = itemListDB.getAllItemNames();
      parts = itemListDB.getAllParts();
      barcodes = itemListDB.getAllBarcodes();
  
      itemListDB.close();
  
  }
  </code></pre>
  
  <p>And since I can't update the UI in the <code>doInBackground()</code> method, I call my <code>setAutoCompeteTextViews()</code> method in the <code>onPostExecute()</code> method of my thread:</p>
  
  <pre><code>public void setAutoCompeteTextViews(){
  
      adapter = new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_list_item_1, brands);
      brandACTV.setAdapter(adapter);
      brandACTV.setThreshold(1);
  
      adapter = new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_list_item_1, items);
      itemACTV.setAdapter(adapter);
      itemACTV.setThreshold(1);
  
      adapter = new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_list_item_1, parts);
      partACTV.setAdapter(adapter);
      partACTV.setThreshold(1);
  
      adapter = new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_list_item_1, barcodes);
      barcodeACTV.setAdapter(adapter);
      barcodeACTV.setThreshold(1);
  
  }
  </code></pre>
  
  <p>For my XML, I'll only show how I wrote one AutoCompleteTextView since they're all similar, only the <code>id</code> vary.</p>
  
  <pre><code>&lt;AutoCompleteTextView 
      android:id="@+id/actvBrand"
      android:layout_width="250dp"
      android:layout_height="wrap_content"
      android:layout_above="@+id/price"
      android:layout_alignLeft="@+id/submit"
      android:ems="10"
      android:hint="Brand"
      android:onClick="actvClicked" /&gt;
  </code></pre>
  
  <p>And I define my <code>actvClicked()</code> function in my activity as follows:</p>
  
  <pre><code>public void actvClicked(View view){
      switch (view.getId()) {
          case R.id.actvBrand:
              Log.d("Hi", "Brand pressed");
              break;
  
          case R.id.actvItemName:
              Log.d("Hi", "Item name pressed");
              break;
  
          case R.id.actvPart:
              Log.d("Hi", "Part pressed");
              break;
  
          case R.id.actvBarcode:
              Log.d("Hi", "Barcode pressed");
              break;
      }
  }
  </code></pre>
  
  <p>However, it does not work and logCat gives me this error:</p>
  
  <pre><code>04-25 15:40:28.270: E/AndroidRuntime(24104): FATAL EXCEPTION: main
  04-25 15:40:28.270: E/AndroidRuntime(24104): Process: com.agict.marswin, PID: 24104
  04-25 15:40:28.270: E/AndroidRuntime(24104): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.agict.marswin/com.agict.marswin.SearchPage}: android.view.InflateException: Binary XML file line #73: Error inflating class android.widget.AutoCompleteTextView
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at android.app.ActivityThread.access$800(ActivityThread.java:135)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at android.os.Handler.dispatchMessage(Handler.java:102)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at android.os.Looper.loop(Looper.java:136)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at android.app.ActivityThread.main(ActivityThread.java:5017)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at java.lang.reflect.Method.invokeNative(Native Method)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at java.lang.reflect.Method.invoke(Method.java:515)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at dalvik.system.NativeStart.main(Native Method)
  04-25 15:40:28.270: E/AndroidRuntime(24104): Caused by: android.view.InflateException: Binary XML file line #73: Error inflating class android.widget.AutoCompleteTextView
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at android.view.LayoutInflater.createView(LayoutInflater.java:620)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at android.app.Activity.setContentView(Activity.java:1929)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at com.agict.marswin.SearchPage.onCreate(SearchPage.java:39)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at android.app.Activity.performCreate(Activity.java:5231)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    ... 11 more
  04-25 15:40:28.270: E/AndroidRuntime(24104): Caused by: java.lang.reflect.InvocationTargetException
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at java.lang.reflect.Constructor.constructNative(Native Method)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at android.view.LayoutInflater.createView(LayoutInflater.java:594)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    ... 24 more
  04-25 15:40:28.270: E/AndroidRuntime(24104): Caused by: java.lang.NullPointerException
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at android.widget.AutoCompleteTextView$PassThroughClickListener.access$302(AutoCompleteTextView.java:1242)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at android.widget.AutoCompleteTextView.setOnClickListener(AutoCompleteTextView.java:200)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at android.view.View.&lt;init&gt;(View.java:3797)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at android.widget.TextView.&lt;init&gt;(TextView.java:623)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at android.widget.EditText.&lt;init&gt;(EditText.java:60)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at android.widget.AutoCompleteTextView.&lt;init&gt;(AutoCompleteTextView.java:137)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    at android.widget.AutoCompleteTextView.&lt;init&gt;(AutoCompleteTextView.java:133)
  04-25 15:40:28.270: E/AndroidRuntime(24104):    ... 27 more
  </code></pre>
  
  <p>And where <code>com.agict.marswin.SearchPage.onCreate(SearchPage.java:39)</code> points to my <code>setContentView()</code> call in my <code>onCreate()</code> function.</p>
  
  <p>I'm sorry but I can't find any mistakes since I declared the function properly and there's nothing missing in my Java file that the XML would look for.</p>
  
  <p>I'm confused and I don't know how to proceed. I would appreciate any guidance and help. Thank you.</p>