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

  • SEARCH
  • Home
  • 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 8400701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:37:35+00:00 2026-06-09T21:37:35+00:00

I’m trying to display a couple of dialogs when a button is pressed, one

  • 0

I’m trying to display a couple of dialogs when a button is pressed, one after the other, and can’t get the second to display. The first one is simply a development stub to replace a validation process during development…

@Override
public void onCreate(Bundle savedInstanceState)
{
  <snip>

  btnLogin.setOnClickListener(new View.OnClickListener()
     {
        public void onClick(View v)
        {
           <snip>

           VerifyLogin(userName, 
                       password);
        }
     });
}

…and…

private void VerifyLogin(String userName,
                        String password)
{
  boolean ok = false;

  if ((userName.length() > 0) && (password.length() > 0))
     ok = DevStub(); // <- Mimics server validation, allows dev. to choose success or not

  <snip>
}

…and…

private boolean DevStub()
{
  new AlertDialog.Builder(this)
     .setTitle("DEVELOPMENT")
     .setMessage("Login: Successful or Not")
     .setPositiveButton("Successful",
                        <snip>
                       )
     .setNegativeButton("Not Successful",
                        new DialogInterface.OnClickListener()
                           {
                              public void onClick(DialogInterface dialog, int which)
                              {
                                  new AlertDialog.Builder(getApplicationContext())
                                     .setTitle("Invalid Username/Password")
                                     .setMessage("Try Again or Recover your password")
                                     .setPositiveButton( <snip> )
                                     .setNegativeButton( <snip> )
                                     .show();
                              }
                           })
     .show();

  return success;
}

As I say, this is only while I develop the interface, then the DevStub() will be replaced by a real login validation but I’d like to understand what I’ve got wrong here. When I tap the “Not Successful” button i simply get an exception.

I’m thinking it has something to do with the getApplicationContext() in the inner dialog but, then again, I don’t know – any suggestions, please?

Logcat:

E/SKIA(12620): FimgApiStretch:stretch failed
D/AndroidRuntime(12620): Shutting down VM
W/dalvikvm(12620): threadid=1: thread exiting with uncaught exception (group=0x40c581f8)
E/AndroidRuntime(12620): FATAL EXCEPTION: main
E/AndroidRuntime(12620): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
E/AndroidRuntime(12620):    at android.view.ViewRootImpl.setView(ViewRootImpl.java:706)
E/AndroidRuntime(12620):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:316)
E/AndroidRuntime(12620):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:218)
E/AndroidRuntime(12620):    at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:143)
E/AndroidRuntime(12620):    at android.app.Dialog.show(Dialog.java:278)
E/AndroidRuntime(12620):    at android.app.AlertDialog$Builder.show(AlertDialog.java:932)
E/AndroidRuntime(12620):    at com.mtbsoft.wud.LoginActivity$2.onClick(LoginActivity.java:62)
E/AndroidRuntime(12620):    at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:168)
E/AndroidRuntime(12620):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(12620):    at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(12620):    at android.app.ActivityThread.main(ActivityThread.java:4514)
E/AndroidRuntime(12620):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(12620):    at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(12620):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
E/AndroidRuntime(12620):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
E/AndroidRuntime(12620):    at dalvik.system.NativeStart.main(Native Method)
D/dalvikvm(12620): GC_CONCURRENT freed 148K, 4% free 13223K/13639K, paused 2ms+4ms
  • 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-06-09T21:37:37+00:00Added an answer on June 9, 2026 at 9:37 pm

    You cannot create a Dialog using an Application Context, it must be an Activity Context, specifically, the Activity that it lives in.

    Try something like this:

    final Context context = this;
    new AlertDialog.Builder(context)
     .setTitle("DEVELOPMENT")
     .setMessage("Login: Successful or Not")
     .setPositiveButton("Successful",
                        <snip>
                       )
     .setNegativeButton("Not Successful",
                        new DialogInterface.OnClickListener()
                           {
                              public void onClick(DialogInterface dialog, int which)
                              {
                                  dialog.dismiss(); //you probably want to add this...
                                  new AlertDialog.Builder(context)
                                     .setTitle("Invalid Username/Password")
                                     .setMessage("Try Again or Recover your password")
                                     .setPositiveButton( <snip> )
                                     .setNegativeButton( <snip> )
                                     .show();
                              }
                           })
     .show();
    
    return success;
    

    Also, note that I added a dialog.dismiss() in the negativeButton OnClickListener.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to select an H1 element which is the second-child in its group
I'm making a simple page using Google Maps API 3. My first. One marker
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:

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.