Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1113639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:53:17+00:00 2026-05-17T02:53:17+00:00

I created a custom AlertDialog to display a Spinner and some EditText elements. When

  • 0

I created a custom AlertDialog to display a Spinner and some EditText elements. When I select a menu option, this custom AlertDialog gets launched. Everything works fine until I actually select the spinner to try and select an item, at which point I get the BadTokenException. I’ve read other StackOverflow posts saying that similiar exceptions were the result of trying to display a diaglog using getApplicationContext() rather than passing Activity.this. I’m not explicitly passing getApplicationContext() to anything related to this AlertDialog.

To setup this custom AlertDiaglog, I created a layout file containing the Spinner and EditText elements, and then made the AlertDialog use that layout:

LayoutInflater inflater = (LayoutInflater)getApplication().getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_layout, (ViewGroup)findViewById(R.id.custom_layout_root));
spinner = (Spinner)layout.findViewById(R.id.custom_layout_spinner);
ArrayAdapter adap = ArrayAdapter.createFromResource(Activity.this, R.array.data, android.R.layout.simple_spinner_item);
adap.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adap);
spinner.setOnItemSelectedListener(new SpinnerItemListener());

AlertDialog.Builder dialog = new AlertDialog.Builder(Activity.this);
dialog.setTitle("Title");
dialog.setPositiveButton("Ok", new Dialog.OnClickListener() ...
...
dialog.show();

This code all works fine for displaying the AlertDialog. However, when I actually touch the Spinner, I get the following problem:

Thread [<3> main] (Suspended (exception WindowManager$BadTokenException)) 
ViewRoot.handleMessage(Message) line: 1704
ViewRoot(Handler).dispatchMessage(Message) line: 99 
Looper.loop() line: 123 
ActivityThread.main(String[]) line: 4203
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 521
ZygoteInit$MethodAndArgsCaller.run() line: 791
ZygoteInit.main(String[]) line: 549
NativeStart.main(String[]) line: not available [native method]

Does anyone have an idea of what’s going on? The exception message says:

Unable to add window -- token null is not for an application

I believe this is the message others have seen for this type of problem, so I’m assuming that ApplicationContext is somewhere in the mix, but I’m not sure where. My manifest is setup with minSdk of 1.5 with a Target SDK of 1.6.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T02:53:17+00:00Added an answer on May 17, 2026 at 2:53 am

    I’ve read other StackOverflow posts saying that similiar exceptions were the result of trying to display a diaglog using getApplicationContext() rather than passing Activity.this.
    I’m not explicitly passing getApplicationContext() to anything related to this AlertDialog.

    Presumably this line of code actually is doing just that — you’re asking the Application to use its context to access a service, rather than that of the current Window:

    LayoutInflater inflater = 
      (LayoutInflater) getApplication().getSystemService(LAYOUT_INFLATER_SERVICE);
    

    Can’t you just replace that with the version below, since you’re launching the AlertDialog from an Activity?

    LayoutInflater inflater =
      (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
    

    Or even simpler:

    LayoutInflater inflater = getLayoutInflater();

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a custom AlertDialog with multiple EditText fields using a custom layout.
I have created a custom alertdialog by the following code: AlertDialog.Builder builder; AlertDialog alertDialog;
This question has been asked before: AlertDialog custom title has black border But was
I'm created a custom AlertDialog, but it have a default black border. How can
I have created a custom adapter to display different images in the each list
I have issue with displaying AlertDialog from Service. I am able to display custom
I'm trying to create a DialogFragment using a custom view in an AlertDialog .
I'm trying to make a custom dialog to show a view in this dialog.
I added a custom menu to the menu button using the following code: @Override
I've created custom button derived from a normal .Net button and have added the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.