gpt4 book ai didi

android - 传递上下文时出错

转载 作者:行者123 更新时间:2023-11-29 22:25:22 25 4
gpt4 key购买 nike

我正在尝试将上下文从一个类传递到另一个类。

调用类:

  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();
}

我什至尝试提供“getContext()”而不是传递“v.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

请为此提供解决方案。

在这方面的任何帮助将不胜感激。

最好的问候,罗尼

最佳答案

尝试传递 YourActivityName.this 而不是 getContext()。希望这会有所帮助。

关于android - 传递上下文时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6111395/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com