我正在尝试在自定义适配器中使用AsuncTask。当我试图使用
时class UpdateProductVariantTask extends AsyncTask<String, String, Void> {
private ProgressDialog progressDialog = new ProgressDialog(context);
String result = "";
protected void onPreExecute() {
progressDialog.setCancelable(false);
progressDialog.setMessage("Please wait.....");
progressDialog.show();
progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface arg0) {
UpdateProductVariantTask.this.cancel(true);
}
});
}
}
我收到此错误:
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
行progressDialog.show();
如何解决此错误?
答案 0 :(得分:2)
尝试使用Activity而不是上下文。
private ProgressDialog progressDialog = new ProgressDialog(activity);