Error Unable to add window -- token null is not for an application
android, progress-bar
Solution
progressBar = new ProgressDialog(getApplicationContext());
in place of getApplicationContext() pass ur ActivityName.this or getContext()
Problem
It is activity display a dialogue window with a positive button . on clicking on button it will go to `Staticdisplay` activity . I am trying to add progress bar while loading activity . I am getting the following error.`$BadTokenException: Unable to add window -- token null is not for an application ` this is code for adding process bar.. `progressBar.show();` I am getting error in this line. how can I get out of this error. thanks. ``` AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setCustomTitle(title); builder.setMessage(R.string.app_description).setPositiveButton( "Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { if (Registration.isRunning == false) { startService(new Intent( getApplicationContext(), Registration.class)); } staticInfo(); if (Registration.ruid == null) Registration.ruid = uId; progressBar = new ProgressDialog( getApplicationContext()); progressBar.setCancelable(true); progressBar.setMessage("Loading Activity..."); progressBar .setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressBar.setProgress(0); progressBar.setMax(100); progressBar.show(); progressBarStatus = 0; new Thread(new Runnable() { public void run() { while (progressBarStatus < 100) { progressBarStatus = 100; progressBarHandler.post(new Runnable() { public void run() { progressBar .setProgress(progressBarStatus); } }); } if (progressBarStatus >= 100) { progressBar.dismiss(); startActivity(new Intent( getApplicationContext(), StatisticDisplay.class)); } } }).start(); } }); AlertDialog alert = builder.create(); alert.show(); } else { startActivity(new Intent(getApplicationContext(), StatisticDisplay.class)); } } ```