java - 尝试访问类中定义的 ArrayList 时出现 NoSuchFieldError
问题描述
我正在尝试访问类来宾中定义的 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(某个值)”时出现错误
任何建议将不胜感激。
解决方案
这应该工作
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);
}
}
推荐阅读
- python - 为什么导入查询在我的 Python 代码中不起作用?
- mongodb - 小数据库上的 mongodrop 慢
- javascript - 如何删除数组中的重复对象并保持最小值
- javascript - Java 和 Node.js lovechild 到 exe
- javascript - 给定一个数组 A,将它与 React useState 对象中的数组 B 连接起来
- flutter - Flutter useAnimationController 钩子不会重建小部件
- swift - 如何使用 UserDefaults 保存数组中的位置和视图计数?
- python - 如何防止未定义数量的文本超出 tkinter 窗口?
- c# - 从 WinUI 3.0 Preview 3 Desktop App 中 WebView2 中的帖子获取响应
- java - 如何在 Java 中为 SQLITE 数据库的不同行实例化多个对象?