它是活动显示一个带有肯定按钮的对话窗口。单击按钮将进入Staticdisplay
活动。我正在尝试在加载活动时添加进度条。我收到以下错误。$BadTokenException: Unable to add window -- token null is not for an application
这是添加进程栏的代码。progressBar.show();
我在这一行出现错误。我怎样才能摆脱这个错误。谢谢。
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));
}
}