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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:26:10+00:00 2026-06-10T14:26:10+00:00

recently I followed a tutorial on how to create an alert dialog and when

  • 0

recently I followed a tutorial on how to create an alert dialog and when i click on delete button, it should show me an alert before deleting but it crashed instead. Can someone tell me where my error lies?

Below is my code:

// Delete button click event
    btnDeleteEvent.setOnClickListener(new View.OnClickListener() {

        public void onClick(View arg0) {
            // alerting user before deleting event
            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                    getApplicationContext());
            // set title
            alertDialogBuilder.setTitle("Warning!");
            // set dialog message
            alertDialogBuilder
                    .setMessage("Are you sure to delete event?")
                    .setCancelable(false)
                    .setPositiveButton("Yes",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                        int id) {
                                    // if yes, deleting event in background
                                    // thread
                                    new DeleteEvent().execute();
                                }
                            })
                    .setNegativeButton("No",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                        int id) {
                                    // if this button is clicked, just close
                                    // the dialog box and do nothing
                                    dialog.cancel();
                                }
                            });

            // create alert dialog
            AlertDialog alertDialog = alertDialogBuilder.create();

            // show it
            alertDialog.show();
        }
    });

Here is my logcat:

08-18 02:02:45.804: E/AndroidRuntime(1288): FATAL EXCEPTION: main
08-18 02:02:45.804: E/AndroidRuntime(1288): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
08-18 02:02:45.804: E/AndroidRuntime(1288):     at android.view.ViewRoot.setView(ViewRoot.java:509)
08-18 02:02:45.804: E/AndroidRuntime(1288):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
08-18 02:02:45.804: E/AndroidRuntime(1288):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
08-18 02:02:45.804: E/AndroidRuntime(1288):     at android.app.Dialog.show(Dialog.java:241)
08-18 02:02:45.804: E/AndroidRuntime(1288):     at com.stts.sparetimetradingsystem.employer.EditEventActivity$5.onClick(EditEventActivity.java:270)
08-18 02:02:45.804: E/AndroidRuntime(1288):     at android.view.View.performClick(View.java:2408)
08-18 02:02:45.804: E/AndroidRuntime(1288):     at android.view.View$PerformClick.run(View.java:8816)
08-18 02:02:45.804: E/AndroidRuntime(1288):     at android.os.Handler.handleCallback(Handler.java:587)
08-18 02:02:45.804: E/AndroidRuntime(1288):     at android.os.Handler.dispatchMessage(Handler.java:92)
08-18 02:02:45.804: E/AndroidRuntime(1288):     at android.os.Looper.loop(Looper.java:123)
08-18 02:02:45.804: E/AndroidRuntime(1288):     at android.app.ActivityThread.main(ActivityThread.java:4627)
08-18 02:02:45.804: E/AndroidRuntime(1288):     at java.lang.reflect.Method.invokeNative(Native Method)
08-18 02:02:45.804: E/AndroidRuntime(1288):     at java.lang.reflect.Method.invoke(Method.java:521)
08-18 02:02:45.804: E/AndroidRuntime(1288):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-18 02:02:45.804: E/AndroidRuntime(1288):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-18 02:02:45.804: E/AndroidRuntime(1288):     at dalvik.system.NativeStart.main(Native Method)
  • 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-10T14:26:11+00:00Added an answer on June 10, 2026 at 2:26 pm

    Try using the Activity’s context instead of the application context

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

Sidebar

Related Questions

Right, hi guys, I recently followed a tutorial http://xnadevelopment.com/tutorials/thestateofthings/thestateofthings.shtml where I wanted to create
I recently followed a small tutorial on howto install apache on a systems where
So I recently followed this tutorial on making a basic chatroom in Java. It
I recently followed this tutorial for GWT: GWT Tutorial I am new to web
I recently followed this tutorial on Google Cloud SQL and GWT: http://code.google.com/apis/sql/docs/developers_guide_java.html I deployed
I recently followed Ray Wenderlich's Cocos2D tutorial for putting Cocos2D in a UIKit app.
I recently followed a way of programming for Android using Scala and Eclipse ,
I recently followed Scott Hansleman's instructions on setting up SSL locally using IIS Express
I recently followed some instructions with RVM to install ruby-debug and I think it
Recently We started on optimizing a database which never followed any standards. We though

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.