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 6769631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:12:59+00:00 2026-05-26T15:12:59+00:00

AlertDialog.Builder builder; AlertDialog alertDialog; Context mContext = getApplicationContext(); LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE); View

  • 0
AlertDialog.Builder builder;
    AlertDialog alertDialog;

    Context mContext = getApplicationContext();
    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.dialoglayout,
                                   (ViewGroup) findViewById(R.id.layout_root));

    TextView text = (TextView) layout.findViewById(R.id.text);
    text.setText("Hello, this is a custom dialog!");
    ImageView image = (ImageView) layout.findViewById(R.id.image);
    image.setImageResource(R.drawable.icon);

    builder = new AlertDialog.Builder(mContext);
    builder.setView(layout);
    alertDialog = builder.create();

    alertDialog.show();

Can anyone tell me the problem with this code .It gives the below exception:

11-06 11:44:20.572: ERROR/AndroidRuntime(339): FATAL EXCEPTION: main
11-06 11:44:20.572: ERROR/AndroidRuntime(339): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.andoroid.dialog/com.andoroid.dialog.AlertDialogTestActivity}: android.view.WindowManager$BadTokenException: Unable to add window — token null is not for an application
11-06 11:44:20.572: ERROR/AndroidRuntime(339): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
11-06 11:44:20.572: ERROR/AndroidRuntime(339): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-06 11:44:20.572: ERROR/AndroidRuntime(339): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-06 11:44:20.572: ERROR/AndroidRuntime(339): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-06 11:44:20.572: ERROR/AndroidRuntime(339): at android.os.Handler.dispatchMessage(Handler.java:99)
11-06 11:44:20.572: ERROR/AndroidRuntime(339): at android.os.Looper.loop(Looper.java:123)
11-06 11:44:20.572: ERROR/AndroidRuntime(339): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-06 11:44:20.572: ERROR/AndroidRuntime(339): at java.lang.reflect.Method.invokeNative(Native Method)
11-06 11:44:20.572: ERROR/AndroidRuntime(339): at java.lang.reflect.Method.invoke(Method.java:521)
11-06 11:44:20.572: ERROR/AndroidRuntime(339): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-06 11:44:20.572: ERROR/AndroidRuntime(339): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-06 11:44:20.572: ERROR/AndroidRuntime(339): at dalvik.system.NativeStart.main(Native Method)
11-06 11:44:20.572: ERROR/AndroidRuntime(339): Caused by: android.view.WindowManager$BadTokenException: Unable to add window — token null is not for an application
11-06 11:44:20.572: ERROR/AndroidRuntime(339): at android.view.ViewRoot.setView(ViewRoot.java:509)
11-06 11:44:20.572: ERROR/AndroidRuntime(339): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
11-06 11:44:20.572: ERROR/AndroidRuntime(339): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
11-06 11:44:20.572: ERROR/AndroidRuntime(339): at android.app.Dialog.show(Dialog.java:241)
11-06 11:44:20.572: ERROR/AndroidRuntime(339): at com.andoroid.dialog.AlertDialogTestActivity.createDialog(AlertDialogTestActivity.java:48)
11-06 11:44:20.572: ERROR/AndroidRuntime(339): at com.andoroid.dialog.AlertDialogTestActivity.onCreate(AlertDialogTestActivity.java:22)
11-06 11:44:20.572: ERROR/AndroidRuntime(339): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-06 11:44:20.572: ERROR/AndroidRuntime(339): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)

  • 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-26T15:12:59+00:00Added an answer on May 26, 2026 at 3:12 pm

    My idea:

    1) use current activity instead of mContext = getApplicationContext(); for example:

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

    this refers to your activity if you are writing code in it.

    2) clear your project

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

Sidebar

Related Questions

I have a very simple dialog defined as: import android.app.AlertDialog; import android.content.Context; import android.view.LayoutInflater;
I'm creating an Alert dialog by using the following: AlertDialog.Builder builder = new AlertDialog.Builder(context);
the AlertDialog.Builder constructor takes a Context as its parameter : AlertDialog.Builder (Context context) ,
I have following code for alertdialog: AlertDialog.Builder helpBuilder = new AlertDialog.Builder(this); helpBuilder.setTitle(Options); helpBuilder.setMessage(Choose Your
Why would one use the AlertDialog.Builder class rather than the methods directly available to
I use below code to show folder list in AlertDialog: ListDialog = new AlertDialog.Builder(MyActivity.this);
Yes, I know there's AlertDialog.Builder, but I'm shocked to know how difficult (well, at
Here's the code I'm using to make a custom AlertDialog. public void onButtonClicked(View v)
I have an AlertDialog.Builder displaying on an application. When I rotate the screen, I
public void popInstructionsDialog(String title, String text, String buttonText, Activity activity){ AlertDialog.Builder builder; AlertDialog alertDialog;

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.