gpt4 book ai didi

java - 尝试访问类中定义的 ArrayList 时出现 NoSuchFieldError

转载 作者:行者123 更新时间:2023-12-01 16:54:14 24 4
gpt4 key购买 nike

我正在尝试访问 guest 类中定义的 ArrayList。但是,我在尝试这样做时遇到了错误。

import java.util.ArrayList;

static class guess{
ArrayList<Integer> box;
ArrayList<Integer> index;
int num;
ArrayList <Boolean> valid;
}
...
guess attempt = new guess();
attempt.box = new ArrayList<Integer>();
attempt.index = new ArrayList<Integer>();
attempt.valid = new ArrayList<Boolean>();

尝试“attempt.box.add(some value)”时出现错误

如有任何建议,我们将不胜感激。

最佳答案

这应该有效

import java.util.ArrayList;

public class Main {
static class guess{
ArrayList<Integer> box;
ArrayList<Integer> index;
int num;
ArrayList <Boolean> valid;
}

public static void main(String[] args) {
guess attempt = new guess();
attempt.box = new ArrayList<Integer>();
attempt.index = new ArrayList<Integer>();
attempt.valid = new ArrayList<Boolean>();
attempt.box.add(22);
}
}

关于java - 尝试访问类中定义的 ArrayList 时出现 NoSuchFieldError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61622418/

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