Android Spinner Error : android.view.WindowManager$BadTokenException: Unable to add window
<p>I want to set the spinner value using String[] or ArrayList.</p>

<p>I have done spinner in other activity working fine.In this activity inside the Tab acivityGroup another Tab activity.</p>

<p>My problem is setting values into spinner. Spinner is displaying correctly Thay means when load the activity , that is working fine but when I click On spinner its give error:</p>

<p>Error is :</p>

<pre><code>    09-30 16:11:37.693: ERROR/AndroidRuntime(699): FATAL EXCEPTION: main
09-30 16:11:37.693: ERROR/AndroidRuntime(699): android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@407f4de8 is not valid; is your activity running?
09-30 16:11:37.693: ERROR/AndroidRuntime(699):     at android.view.ViewRoot.setView(ViewRoot.java:527)
09-30 16:11:37.693: ERROR/AndroidRuntime(699):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
09-30 16:11:37.693: ERROR/AndroidRuntime(699):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
09-30 16:11:37.693: ERROR/AndroidRuntime(699):     at android.view.Window$LocalWindowManager.addView(Window.java:424)
09-30 16:11:37.693: ERROR/AndroidRuntime(699):     at android.app.Dialog.show(Dialog.java:241)
09-30 16:11:37.693: ERROR/AndroidRuntime(699):     at android.app.AlertDialog$Builder.show(AlertDialog.java:802)
09-30 16:11:37.693: ERROR/AndroidRuntime(699):     at android.widget.Spinner.performClick(Spinner.java:260)
09-30 16:11:37.693: ERROR/AndroidRuntime(699):     at android.view.View$PerformClick.run(View.java:9080)
09-30 16:11:37.693: ERROR/AndroidRuntime(699):     at android.os.Handler.handleCallback(Handler.java:587)
09-30 16:11:37.693: ERROR/AndroidRuntime(699):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-30 16:11:37.693: ERROR/AndroidRuntime(699):     at android.os.Looper.loop(Looper.java:123)
09-30 16:11:37.693: ERROR/AndroidRuntime(699):     at android.app.ActivityThread.main(ActivityThread.java:3683)
09-30 16:11:37.693: ERROR/AndroidRuntime(699):     at java.lang.reflect.Method.invokeNative(Native Method)
09-30 16:11:37.693: ERROR/AndroidRuntime(699):     at java.lang.reflect.Method.invoke(Method.java:507)
09-30 16:11:37.693: ERROR/AndroidRuntime(699):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-30 16:11:37.693: ERROR/AndroidRuntime(699):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-30 16:11:37.693: ERROR/AndroidRuntime(699):     at dalvik.system.NativeStart.main(Native Method)
</code></pre>

<p>This is my code :</p>

<pre><code>   View viewToLoad = LayoutInflater.from(this.getParent()).inflate(R.layout.line_discount, null);
    this.setContentView(viewToLoad); 

   ArrayList&lt;String&gt; productList = new ArrayList&lt;String&gt;();
    int size = products.size()+1;
    String[] proList = new String[size];
    proList[0] = "---Select----";

    for(int i = 1; i&lt; size ;i++){
        productList.add(products.get(i-1).getDescription());
        proList[i] = products.get(i-1).getDescription();
    }

    sp = (Spinner)findViewById(R.id.spProList);
    ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt; (LineDiscountActivity.this, android.R.layout.simple_spinner_item, proList);
    sp.setAdapter(adapter);
</code></pre>

<p>This is my image:</p>

<p><img src="http://i.stack.imgur.com/08elV.png" alt="enter image description here"></p>

<p><strong>Problem in TabActivity.Because I have run this part Within the TabActivityGroup. Its was working.When I run  this inside the Tab Activity within TabActivityGroup, then its a problem.
I have TabActivtyGroup &amp;Within that normal TabActivity.</strong></p>

<p>How can I do in this situation?</p>

<p>Please anybody help me</p>

<p>Thanks</p>
