gpt4 book ai didi

java - 方法 userAccounts() 未定义类型 new View.OnClickListener(){}

转载 作者:行者123 更新时间:2023-11-30 03:13:05 28 4
gpt4 key购买 nike

我有一个 userAccounts 类,它声明了我的用户帐户的所有变量。但是,当尝试增加 userAccounts 类型的 arrayList 的大小时按下按钮时,我得到了错误。

The method userAccounts() is undefined for the type new View.OnClickListener(){}

代码是:

public class CreateAccount extends Activity {
ArrayList<userAccounts> accountArray = new ArrayList<userAccounts>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_account);



final Button buttonCreate = (Button) findViewById(R.id.btnCreate);
buttonCreate.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

accountArray.add(userAccounts());

最佳答案

如果您想向列表中添加新项目,您应该将 accountArray.add(userAccounts()) 更改为 accountArray.add(new userAccounts())。您的变体假设您调用了一些专用于监听器类的方法 userAccounts()

关于java - 方法 userAccounts() 未定义类型 new View.OnClickListener(){},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20599657/

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