+ Reply to Thread
Results 1 to 2 of 2

Thread: Spinner makes android application crash

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    14

    Spinner makes android application crash

    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.

    Here's my spinner xml code (which is inside a LinearLayout, if this is useful):
    Code:
     <Spinner
           style="@style/mediumBlackDefault"
           android:id="@+id/spinner"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:layout_weight="4" />
    And here's how I populate it:
    Code:
    Spinner spinner = (Spinner) findViewById(R.id.spinner);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(  
                           getApplicationContext(),R.array.countries_array,
                           android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    Also this is the countries_array:
    
    <string-array name="countries_array">
        <item>AE</item>
        <item>AF</item>
        <item>AG</item>
        <item>AI</item>
        <item>AL</item>
        <item>AM</item>
    </string-array>
    Finally I get these errors:
    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)
    I've read all the posts available and none solved my problem.

  2. #2
    Junior Member
    Join Date
    Jul 2012
    Posts
    8
    I would suggest you to try passing YourActivityName.this instead of getApplicationContext() as Context to your adapter.

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts