Stack Exchange
How to call spinner in tab Activity?
I want to call spinner in tab activity.I already do that but it's generate such error.
Error is 03-20 17:08:08.397: E/AndroidRuntime(347): android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@405ee8b8 is not valid; is your activity running?

My code
        Cursor cursor = null;
    try{
    senderId=(Spinner)findViewById(R.id.spinner1);
    String[] emailAddress={};
    Uri uri=Uri.parse("content://com.android.email.provider/account");
    String[] projection={"emailAddress"};
    ArrayList<String> emailList=new ArrayList<String>();
    cursor=getContentResolver().query(uri, projection, null, null, null);
    cursor.moveToFirst();
    while(!cursor.isAfterLast())
    {
        emailList.add(cursor.getString(cursor.getColumnIndex("emailAddress")));
        cursor.moveToNext();
    }
    emailAddress = (String[]) emailList.toArray(new String[0]);
    @SuppressWarnings({ "unchecked", "rawtypes" })
    ArrayAdapter<CharSequence> adapterCountry=new ArrayAdapter(getParent(),android.R.layout.simple_spinner_item,emailAddress);
    adapterCountry.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    senderId.setAdapter(adapterCountry);
    //senderId.setAdapter(new  ArrayAdapter<String>(mContext,android.R.layout.simple_spinner_item, emailAddress));
    }catch (Exception e) {
        // TODO: handle exception
    }
    finally{
        cursor.close();
    }


can you paste the whole code?

You are using a bad context here so try to inflate your layout using LayoutInflater and setContentView(view_inflated); like below,
View view = LayoutInflater.from(getParent()).inflate(R.layout.your_xml, null);
setContentView(view);
your_spinner = (Spinner)view.findViewById(R.id.your_spinner_id);

