title: Spinner makes android application crash
body: <p>I'm using a spinner to show countries ID. Everything seems fine until I run the app and click on the spinner. After I click on the spinner the app crash.</p>
  
  <p>Here's my spinner xml code (which is inside a LinearLayout, if this is useful):</p>
  
  <pre><code> &lt;Spinner
         style="@style/mediumBlackDefault"
         android:id="@+id/spinner"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:layout_weight="4" /&gt;
  </code></pre>
  
  <p>And here's how I populate it:</p>
  
  <pre><code>Spinner spinner = (Spinner) findViewById(R.id.spinner);
  ArrayAdapter&lt;CharSequence&gt; adapter = ArrayAdapter.createFromResource(  
                         getApplicationContext(),R.array.countries_array,
                         android.R.layout.simple_spinner_item);
  adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  </code></pre>
  
  <p>Also this is the countries_array:</p>
  
  <pre><code>&lt;string-array name="countries_array"&gt;
      &lt;item&gt;AE&lt;/item&gt;
      &lt;item&gt;AF&lt;/item&gt;
      &lt;item&gt;AG&lt;/item&gt;
      &lt;item&gt;AI&lt;/item&gt;
      &lt;item&gt;AL&lt;/item&gt;
      &lt;item&gt;AM&lt;/item&gt;
  &lt;/string-array&gt;
  </code></pre>
  
  <p>Finally I get these errors:</p>
  
  <pre><code>03-09 11:39:36.944: E/AndroidRuntime(990): FATAL EXCEPTION: main
  03-09 11:39:36.944: E/AndroidRuntime(990): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
  03-09 11:39:36.944: E/AndroidRuntime(990):  at android.view.ViewRootImpl.setView(ViewRootImpl.java:519)
  03-09 11:39:36.944: E/AndroidRuntime(990):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:279)
  03-09 11:39:36.944: E/AndroidRuntime(990):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:193)
  03-09 11:39:36.944: E/AndroidRuntime(990):  at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:118)
  03-09 11:39:36.944: E/AndroidRuntime(990):  at android.app.Dialog.show(Dialog.java:274)
  03-09 11:39:36.944: E/AndroidRuntime(990):  at android.app.AlertDialog$Builder.show(AlertDialog.java:932)
  03-09 11:39:36.944: E/AndroidRuntime(990):  at android.widget.Spinner$DialogPopup.show(Spinner.java:672)
  03-09 11:39:36.944: E/AndroidRuntime(990):  at android.widget.Spinner.performClick(Spinner.java:435)
  03-09 11:39:36.944: E/AndroidRuntime(990):  at android.view.View$PerformClick.run(View.java:13983)
  03-09 11:39:36.944: E/AndroidRuntime(990):  at android.os.Handler.handleCallback(Handler.java:605)
  03-09 11:39:36.944: E/AndroidRuntime(990):  at android.os.Handler.dispatchMessage(Handler.java:92)
  03-09 11:39:36.944: E/AndroidRuntime(990):  at android.os.Looper.loop(Looper.java:137)
  03-09 11:39:36.944: E/AndroidRuntime(990):  at android.app.ActivityThread.main(ActivityThread.java:4340)
  03-09 11:39:36.944: E/AndroidRuntime(990):  at java.lang.reflect.Method.invokeNative(Native Method)
  03-09 11:39:36.944: E/AndroidRuntime(990):  at java.lang.reflect.Method.invoke(Method.java:511)
  03-09 11:39:36.944: E/AndroidRuntime(990):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
  03-09 11:39:36.944: E/AndroidRuntime(990):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
  03-09 11:39:36.944: E/AndroidRuntime(990):  at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>I've read all the posts available and none solved my problem.</p>
  
  <p>Many thanks in advance!</p>