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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:58:45+00:00 2026-05-24T23:58:45+00:00

hi friends i download one popup window sample source code…its working fine…when i run

  • 0

hi friends i download one popup window sample source code…its working fine…when i run this application emulator screen display one button, if i click that button popup window shown in bottom.if i click again same button its dismiss the popup window…but,

i expect when my application open i need static popup window, no need this button. then i click softkey board(computer keyboard)f2 button, the popup window i want to dismiss…thats all if anyone know please help me……

This is my source code:

package popupTest.popupTest;

import android.R.layout;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

public class popupTest extends Activity {

 PopupWindow popUp;
 LinearLayout layout;
 TextView tv;
 LayoutParams params;
 LinearLayout mainLayout;
 Button but;
 boolean click = true;

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  popUp = new PopupWindow(this);
  layout = new LinearLayout(this);
  mainLayout = new LinearLayout(this);
  tv = new TextView(this);
  but = new Button(this);
  but.setText("Click Me");
  but.setOnClickListener(new OnClickListener() {

   public void onClick(View v) {
    if (click) {
     popUp.showAtLocation(layout, Gravity.BOTTOM, 10, 10);
     popUp.update(50, 50, 300, 80);
     click = false;
    } else {
     popUp.dismiss();
     click = true;
    }
   }

  });
  params = new LayoutParams(LayoutParams.WRAP_CONTENT,
    LayoutParams.WRAP_CONTENT);
  layout.setOrientation(LinearLayout.VERTICAL);
  tv.setText("Hi this is a sample text for popup window");
  layout.addView(tv, params);
  popUp.setContentView(layout);
  // popUp.showAtLocation(layout, Gravity.BOTTOM, 10, 10);
  mainLayout.addView(but, params);
  setContentView(mainLayout);
 }
}

logcat error:

    08-23 16:38:23.771: ERROR/AndroidRuntime(433): FATAL EXCEPTION: main
08-23 16:38:23.771: ERROR/AndroidRuntime(433): java.lang.RuntimeException: Unable to start activity ComponentInfo{popupTest.popupTest/popupTest.popupTest.popupTest}: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
08-23 16:38:23.771: ERROR/AndroidRuntime(433):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
08-23 16:38:23.771: ERROR/AndroidRuntime(433):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-23 16:38:23.771: ERROR/AndroidRuntime(433):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-23 16:38:23.771: ERROR/AndroidRuntime(433):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-23 16:38:23.771: ERROR/AndroidRuntime(433):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-23 16:38:23.771: ERROR/AndroidRuntime(433):     at android.os.Looper.loop(Looper.java:123)
08-23 16:38:23.771: ERROR/AndroidRuntime(433):     at android.app.ActivityThread.main(ActivityThread.java:4627)
08-23 16:38:23.771: ERROR/AndroidRuntime(433):     at java.lang.reflect.Method.invokeNative(Native Method)
08-23 16:38:23.771: ERROR/AndroidRuntime(433):     at java.lang.reflect.Method.invoke(Method.java:521)
08-23 16:38:23.771: ERROR/AndroidRuntime(433):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-23 16:38:23.771: ERROR/AndroidRuntime(433):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-23 16:38:23.771: ERROR/AndroidRuntime(433):     at dalvik.system.NativeStart.main(Native Method)
08-23 16:38:23.771: ERROR/AndroidRuntime(433): Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
08-23 16:38:23.771: ERROR/AndroidRuntime(433):     at android.view.ViewRoot.setView(ViewRoot.java:505)
08-23 16:38:23.771: ERROR/AndroidRuntime(433):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
08-23 16:38:23.771: ERROR/AndroidRuntime(433):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
08-23 16:38:23.771: ERROR/AndroidRuntime(433):     at android.view.Window$LocalWindowManager.addView(Window.java:424)
08-23 16:38:23.771: ERROR/AndroidRuntime(433):     at android.widget.PopupWindow.invokePopup(PopupWindow.java:828)
08-23 16:38:23.771: ERROR/AndroidRuntime(433):     at android.widget.PopupWindow.showAtLocation(PopupWindow.java:688)
08-23 16:38:23.771: ERROR/AndroidRuntime(433):     at popupTest.popupTest.popupTest.onCreate(popupTest.java:49)
08-23 16:38:23.771: ERROR/AndroidRuntime(433):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-23 16:38:23.771: ERROR/AndroidRuntime(433):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-23 16:38:23.771: ERROR/AndroidRuntime(433):     ... 11 more
08-23 16:38:23.820: WARN/ActivityManager(59):   Force finishing activity popupTest.popupTest/.popupTest
  • 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-24T23:58:46+00:00Added an answer on May 24, 2026 at 11:58 pm

    put the code outside onClick in onCreate ….and use setOnclickListener to remove ur popup..

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

Sidebar

Related Questions

Friends its really giving me a great head ache about the problem I am
friends, i have created custom title bar using following titlebar.xml file with code <?xml
I've written a small java program to download all friends' and followers' profile pictures
I'm working on small open source project for developed Windows. I created new project
So in keeping with my last question, I'm working on scraping the friends feed
I want to integrate my application to Facebook. I download the Facebook BB Sdk
I'm working with a friend on a web application we'd like to distribute and
friends, i dont see request timeout in KSoap library any one guide me what
I'm working on a program in Visual C# 2010 for a friends company and
hello friends I need to download mp3 file from the internet and to store

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.