我试图将上下文从一个类传递到另一个类。传递上下文时出错
调用类:
mForgotPatternButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
new ListOfAccounts(v.getContext());
}
});
称为类:
public ListOfAccounts(Context context) {
super(context);
mAccounts = new ArrayList<String>();
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Select the account");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(),R.layout.list_all_accounts, mAccounts);
AccountManager.get(context).addOnAccountsUpdatedListener(ListOfAccounts.this, null, true);
builder.setAdapter(adapter, new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialogInterface, int item) {
mCallback.forgotPattern(true);
return;
}
});
builder.create().show();
}
不是传递 “v.getContext()” 中,我甚至试图让 “的getContext()”。但是在所有情况下,我会得到以下例外
05-24 16:11:27.087: ERROR/AndroidRuntime(4429): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
请为此提供解决方案。
在这方面的任何帮助将不胜感激。
最好的问候, 罗尼
可能重复的[Android:ProgressDialog.show()崩溃与getApplicationContext](http://stackoverflow.com/questions/1561803/android-progressdialog-show-crashes-with-getapplicationcontext) – 2011-05-25 11:02:14