title: Application implementing AutoCompleteTextView crashing at startup
body: <p>I am working on an application that uses <code>AutoCompleteTextView</code> and switches between <code>Activities</code> according to the option selected. But, now my application is crashing down at startup. I can't understand why. Please help.</p>
  
  <pre><code>import android.os.Bundle;
  import android.app.Activity;
  import android.content.Intent;
  import android.view.Menu;
  import android.view.View;
  import android.widget.AdapterView;
  import android.widget.AdapterView.OnItemClickListener;
  import android.widget.AdapterView.OnItemSelectedListener;
  import android.widget.ArrayAdapter;
  import android.widget.AutoCompleteTextView;
  import android.widget.Toast;
  import android.view.inputmethod.InputMethodManager;
  
  
  public class MainActivity extends Activity {
  
  String[] presidents= {
                      "John F. Kennedy",
                      "Lyndon B. Johnson",
                      "Richard Nixon",
                      "Gerald Ford",
                      "Jimmy Carter",
                      "Ronald Reagan",
                      "George H. W. Bush",
                      "Bill Clinton",
                      "George W. Bush",
                      "Barack Obama"
                      };
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
      ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.select_dialog_item, presidents);
  
      textView.setThreshold(3);
      textView.setAdapter(adapter);
      textView.setOnItemSelectedListener((OnItemSelectedListener) this);
      textView.setOnItemClickListener((OnItemClickListener) this);
      textView.setOnItemSelectedListener(new OnItemSelectedListener()
      {   
      @Override
      public void onItemSelected(AdapterView&lt;?&gt; parent, View view,
                     int index, long id)
      {
          int position=0;
          if(position == 1){
              Intent i = new Intent (MainActivity.this, SecondActivity.class);
              i.putExtra("KEY", presidents[index]);
              startActivity(i);
              }
      }
  
      @Override
      public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
          // TODO Auto-generated method stub
  
      }
     });
  
      }
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/4wHkD.png" alt="LogCat"></p>
  
  <p>Layout:</p>
  
  <pre><code>&lt;RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context=".MainActivity" &gt;
  
  &lt;AutoCompleteTextView
      android:id="@+id/autoCompleteTextView1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_below="@+id/names"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="20dp"
      android:ems="10" &gt;
  
      &lt;requestFocus /&gt;
  &lt;/AutoCompleteTextView&gt;
  
  &lt;TextView
      android:id="@+id/names"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentTop="true"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="38dp"
      android:text="@string/hello_world" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>