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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:25:17+00:00 2026-06-05T22:25:17+00:00

In my android application, I am using a custom dialog. When I try to

  • 0

In my android application, I am using a custom dialog. When I try to show the dialog, it causes an error. I don’t know what I am doing wrong, and I am really confused.

Here is my code:

protected Dialog onCreateDialog(int id) {
    Dialog dialog;
    switch(id) {
    case 0:
        dialog = new Dialog(getApplicationContext());

        dialog.setContentView(R.layout.paused);
        dialog.setTitle("Game Paused");
        dialog.show();
        break;
    default:
        dialog = null;
    }
    return null;
}

And here is how I show the dialog

showDialog(0);

By the way, it says that showDialog(int) is deprecated.

Android logcat:

> 06-19 18:44:22.399: W/dalvikvm(467): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
06-19 18:44:22.419: E/AndroidRuntime(467): FATAL EXCEPTION: main
06-19 18:44:22.419: E/AndroidRuntime(467): java.lang.IllegalStateException: Could not execute method of the activity
06-19 18:44:22.419: E/AndroidRuntime(467):  at android.view.View$1.onClick(View.java:2072)
06-19 18:44:22.419: E/AndroidRuntime(467):  at android.view.View.performClick(View.java:2408)
06-19 18:44:22.419: E/AndroidRuntime(467):  at android.view.View$PerformClick.run(View.java:8816)
06-19 18:44:22.419: E/AndroidRuntime(467):  at android.os.Handler.handleCallback(Handler.java:587)
06-19 18:44:22.419: E/AndroidRuntime(467):  at android.os.Handler.dispatchMessage(Handler.java:92)
06-19 18:44:22.419: E/AndroidRuntime(467):  at android.os.Looper.loop(Looper.java:123)
06-19 18:44:22.419: E/AndroidRuntime(467):  at android.app.ActivityThread.main(ActivityThread.java:4627)
06-19 18:44:22.419: E/AndroidRuntime(467):  at java.lang.reflect.Method.invokeNative(Native Method)
06-19 18:44:22.419: E/AndroidRuntime(467):  at java.lang.reflect.Method.invoke(Method.java:521)
06-19 18:44:22.419: E/AndroidRuntime(467):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-19 18:44:22.419: E/AndroidRuntime(467):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-19 18:44:22.419: E/AndroidRuntime(467):  at dalvik.system.NativeStart.main(Native Method)
06-19 18:44:22.419: E/AndroidRuntime(467): Caused by: java.lang.reflect.InvocationTargetException
06-19 18:44:22.419: E/AndroidRuntime(467):  at com.jlennon.gametest.PlayGameActivity.pause(PlayGameActivity.java:105)
06-19 18:44:22.419: E/AndroidRuntime(467):  at java.lang.reflect.Method.invokeNative(Native Method)
06-19 18:44:22.419: E/AndroidRuntime(467):  at java.lang.reflect.Method.invoke(Method.java:521)
06-19 18:44:22.419: E/AndroidRuntime(467):  at android.view.View$1.onClick(View.java:2067)
06-19 18:44:22.419: E/AndroidRuntime(467):  ... 11 more
06-19 18:44:22.419: E/AndroidRuntime(467): Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
06-19 18:44:22.419: E/AndroidRuntime(467):  at android.view.ViewRoot.setView(ViewRoot.java:509)
06-19 18:44:22.419: E/AndroidRuntime(467):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
06-19 18:44:22.419: E/AndroidRuntime(467):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
06-19 18:44:22.419: E/AndroidRuntime(467):  at android.app.Dialog.show(Dialog.java:241)
06-19 18:44:22.419: E/AndroidRuntime(467):  at com.jlennon.gametest.PlayGameActivity.onCreateDialog(PlayGameActivity.java:131)
06-19 18:44:22.419: E/AndroidRuntime(467):  at android.app.Activity.onCreateDialog(Activity.java:2472)
06-19 18:44:22.419: E/AndroidRuntime(467):  at android.app.Activity.createDialog(Activity.java:881)
06-19 18:44:22.419: E/AndroidRuntime(467):  at android.app.Activity.showDialog(Activity.java:2547)
06-19 18:44:22.419: E/AndroidRuntime(467):  at android.app.Activity.showDialog(Activity.java:2514)
06-19 18:44:22.419: E/AndroidRuntime(467):  ... 15 more

Thanks a whole lot in advance!

  • 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-05T22:25:18+00:00Added an answer on June 5, 2026 at 10:25 pm

    Try this code

     protected Dialog onCreateDialog(int id) {
      Dialog dialog;
      switch(id) {
       case 0:
        dialog = new Dialog(this);
    
        dialog.setContentView(R.layout.paused);
        dialog.setTitle("Game Paused");
        dialog.show();
        break;
    default:
        dialog = null;
    }
    return null;
    

    }

    I just replaced dialog = new Dialog(getApplicationContext()) to dialog = new Dialog(this);

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

Sidebar

Related Questions

I'm trying to use custom notifications in my Android application using Google's sample from
I am currently using a custom service in my android application to retrieve a
I'm having some errors with my custom recording application using android. I saw most
I am creating an android application using Java. I have a boolean variable called
I'm making an android application using phonegap. I'm using phonegap's Storage api for querying
I am currently developing an android application using eclipse and I already have a
I have developed the Hello World Android application using Eclipse. I can run the
I'm trying to launch a very simple android application using OpenStreetMaps-Tools for Android ,
I'm trying to use CSS3 multi-column column layout in my android application using WebView,
I am developing an application using Android SDK. In this application I am facing

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.