title: Spinner performclick() not working
body: <p>I want the spinner to open up by itself when I run the activity, so I'm using the <code>performClick()</code> method but it's showing this error:</p>
  
  <p>Caused by: <code>android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?</code></p>
  
  <p>What should I do?
  Here is my code</p>
  
  <pre><code>public class FacilityComplaint extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
      private Spinner spinner1;
  
      private static final String[] suggestions = {"Select from suggestions", "Switch not working",
              "Switch faulty", "Switch light not working", "Switch handle faulty"};
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_facility_complaint);
  
          spinner1 = (Spinner) findViewById(R.id.spinner1);
          ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(FacilityComplaint.this,
                  android.R.layout.simple_spinner_item, suggestions);
  
          adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          spinner1.setAdapter(adapter);
          spinner1.setOnItemSelectedListener(this);
          spinner1.performClick();
      }
  
  
      public void onItemSelected(AdapterView&lt;?&gt; parent, View v, int position, long id) {
  
          switch (position) {
              case 0:
                  //do something
                  break;
  
              case 1:
                  //do something
                  break;
  
              case 2:
                  //do something
                  break;
  
              case 3:
                  //do something
                  break;
  
              case 4:
                  //do something
                  break;
          }
      }
  
      public void onNothingSelected(AdapterView&lt;?&gt; parent) {
  
      }
  
  }
  </code></pre>