Progress dialog problem

Put your problem here if it does not fit any of the other categories.

Progress dialog problem

Postby Kyle255 » Wed Apr 13, 2011 11:28 am

I am using android 2.2 and api level 8. I want to make a progress dialog but every time i do it shows this error


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

my class extends Activity

here is my code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. ]ProgressDialog pd;
  2.        
  3.        
  4.         @Override
  5.     public void onCreate(Bundle savedInstanceState) {
  6.         super.onCreate(savedInstanceState);
  7.                 setContentView(R.layout.search);
  8.                
  9.                
  10.                 findProfile = this;
  11.                
  12.                 playerID = (EditText)this.findViewById(R.id.enterSearchid);
  13.                 enter = (Button)this.findViewById(R.id.searchButton);
  14.                
  15.                 enter.setOnClickListener(new OnClickListener(){
  16.  
  17.                                 @Override
  18.                                 public void onClick(View v) {
  19.                                         handle = playerID.getText().toString();
  20.                                        
  21.                                         pd = ProgressDialog.show(getBaseContext(), "Finding ID", "Please wait...", true, false);
  22.                                        
  23.                                         Thread thread = new Thread(FindProfile.this);
  24.                         thread.start();
  25.                                        
  26.                                 }
  27.                        
  28.                 });
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


i also tried this too
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. final Context mycon = this;
  2. pd = ProgressDialog.show(mycon, "Finding ID", "Please wait...", true, false);
  3.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


but every time it shows that error and i dont know what to do. i just want to display a ProgressDialog.
Kyle255
Freshman
Freshman
 
Posts: 8
Joined: Mon Mar 21, 2011 8:45 pm

Top

Re: Progress dialog problem

Postby imbroken » Wed Apr 13, 2011 12:53 pm

You should use getBaseContext or getApplicationContext in a Dialog. Use <MyActivityName>.this.
imbroken
Senior Developer
Senior Developer
 
Posts: 131
Joined: Thu Jan 06, 2011 6:57 pm
Location: Germnay

Re: Progress dialog problem

Postby Kyle255 » Wed Apr 13, 2011 7:46 pm

I did that and i got the same error

I did this. FindProfile is the class with the activity

FindProfile.getApplicationContext()

and

FindProfile.getBaseContext()

it still showed that same error
Kyle255
Freshman
Freshman
 
Posts: 8
Joined: Mon Mar 21, 2011 8:45 pm

Re: Progress dialog problem

Postby imbroken » Wed Apr 13, 2011 8:52 pm

pd = new ProgressDialog(FindProlile.this);
pd.setMessage("Finding ID");
pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
pd.show();

only "this" is not enough because you are the onClickListener class.
imbroken
Senior Developer
Senior Developer
 
Posts: 131
Joined: Thu Jan 06, 2011 6:57 pm
Location: Germnay

Re: Progress dialog problem

Postby Kyle255 » Wed Apr 13, 2011 9:04 pm

ok this is aggravating lol

I did what you said and know i got another error but this one is a little different

Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@4591f288 is not valid; is your activity running?

im guessing that my activity isn't running? but how is that possible
Kyle255
Freshman
Freshman
 
Posts: 8
Joined: Mon Mar 21, 2011 8:45 pm

Re: Progress dialog problem

Postby Kyle255 » Wed Apr 13, 2011 11:19 pm

i finally got it to work!!!

i just replaces this with getParent() so it looks like this.

pd = new ProgressDialog(getParent());
Kyle255
Freshman
Freshman
 
Posts: 8
Joined: Mon Mar 21, 2011 8:45 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot] and 16 guests