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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:05:45+00:00 2026-06-11T13:05:45+00:00

I have a problem with an AlertDialog in Android. In a class Misc there

  • 0

I have a problem with an AlertDialog in Android.
In a class “Misc” there is a method which creates an alertdialog.

public static void getAlert (Context context)
{
Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Notruf absenden?");
builder.setMessage("automatischer Notruf in 60 sec.");
builder.setCancelable(true);
builder.setPositiveButton("Ja", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
               callEmergency(context);
           }
       });
builder.setNegativeButton("Abbrechen", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
              countdown.cancel();
           }
       });

 final AlertDialog alertBox = builder.create();
 alertBox.show();

 countdown = new CountDownTimer(60000, 1000) 
 {
   public void onTick(long millisUntilFinished) 
   {
     alertBox.setMessage("automatischer Notruf in "+ (millisUntilFinished/1000) + " sec.");
   }
   public void onFinish()
   {
   alertBox.cancel();
   callEmergency(context);
   }
}.start();

When I call the method in the main activity by typing:

Misc.getAlert(this)

it works, but in another class named Algorithm I call it in the same way:

Misc.getAlert(context)

But then there is this exception:

09-16 17:15:32.304: E/AndroidRuntime(19797): FATAL EXCEPTION: main
09-16 17:15:32.304: E/AndroidRuntime(19797): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
09-16 17:15:32.304: E/AndroidRuntime(19797):    at android.view.ViewRoot.setView(ViewRoot.java:536)
09-16 17:15:32.304: E/AndroidRuntime(19797):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
09-16 17:15:32.304: E/AndroidRuntime(19797):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
09-16 17:15:32.304: E/AndroidRuntime(19797):    at android.app.Dialog.show(Dialog.java:241)
09-16 17:15:32.304: E/AndroidRuntime(19797):    at de.smehner.Sturzerkennung.Misc.getAlert(Misc.java:220)
09-16 17:15:32.304: E/AndroidRuntime(19797):    at de.smehner.Sturzerkennung.Algorithm.fall(Algorithm.java:203)
09-16 17:15:32.304: E/AndroidRuntime(19797):    at de.smehner.Sturzerkennung.Algorithm.performNonGraphical(Algorithm.java:68)
09-16 17:15:32.304: E/AndroidRuntime(19797):    at de.smehner.Sturzerkennung.SensorValueReceiver.onSensorChanged(SensorValueReceiver.java:66)
09-16 17:15:32.304: E/AndroidRuntime(19797):    at android.hardware.SensorManager$ListenerDelegate$1.handleMessage(SensorManager.java:538)

I tried to set in getAlert

Builder builder = new AlertDialog.Builder(Sturzerkennung.this); // Sturzerkenung is the main activity

But then there is the error: “No enclosing instance of the type Sturzerkennung is accessible in scope”

context.getApplicationContext instead of Sturzerkennung.this didn’t solve the problem either.
Has anybody an idea for this problem?

  • 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-11T13:05:46+00:00Added an answer on June 11, 2026 at 1:05 pm

    Problem solved..
    The context in the Algorithm class was not from the Activity Sturzerkennung…

    In Sturzerkennung I put

    public static Context context;
    ...
    context = this;
    

    and then in Algorithm the parameter for getAlert is

    Misc.getAlert(Sturzerkennung.context)
    

    Now it works..

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

Sidebar

Related Questions

I have problem with context menu. I have got: @Override public void onCreateContextMenu(ContextMenu menu,
I have a very common problem which I think every android developer faces at
I have a class ActivityExitDialogFragment that extends android.support.v4.app.DialogFragment. There are only 2 methods in
I have a problem with KSOAP2 for android with dependencies on an Android device.
i have a problem trying to show an image in an AlertDialog with a
I am having another problem with my android app which I can't find an
I have a problem with a AlertDialog : I'ld like that my AlertDialog return
I'm having a problem displaying an AlertDialog from within the onOptionsItemSelected method. That is,
I have an AlertDialog in and it's got a button, which, if selected, will
I ask to find a problem in my code which crashes application. I have

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.