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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:42:23+00:00 2026-06-16T05:42:23+00:00

I am currently working on an android project and I am having a problem

  • 0

I am currently working on an android project and I am having a problem with contexts and AlertDialogs.

I have a class which extends a Fragment and it creates an instance of a standard Java class called Common which has the context passed to it from the Fragment. In the Common class I have some code to display an alert dialog and return a boolean based on what the user clicked.

With a standard class that extends an Activity I can create the instance of the Common class using the following:

Common common = new Common(this);

Then I can call my show alert dialog function within this class by using the following code.

common.showYesNoDialog("This is my message", false);

The code above works fine, for a standard Activity class. My problem is this.

In my Class that Extends Fragment I can’t pass this to the common class so I instead have to use the following code:

Common common = new Common(getActivity().getApplicationContext());

and I use the following code as normal:

common.showYesNoDialog("This is my message", false);

When I call the function above I get the following error:

FATAL EXCEPTION: main
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application.

Thanks for any help you can provide.

  • 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-16T05:42:24+00:00Added an answer on June 16, 2026 at 5:42 am

    You should use getActivity() instead of getActivity().getApplicationContext() since getActivity() returns an Activity which is a subclass of Context.

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

Sidebar

Related Questions

I am currently working on an android project and I am having an issue
I am currently working on android project where I want to have a text
I am currently working on an android project which lists all of the apps
I am currently working on an android project and I have an activity, lets
I am currently working on an android project. I am trying to have an
I'm currently working on debugging some code with my android project. I'm having an
I have a android project, I am working on and it, currently does not
Possible Duplicate: findViewById in fragment android I am currently working on android project and
Problem Statement:- I am working on the android project in which I need to
I'm currently working on an Android project, where I have to collect data from

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.