我有以下代码:
public class Table {
Table2[] data = new Table2[2000];
public Table() {
for (int i = 0; i < data.length; i++) {
data[i] = new Table2();
}
}
}
还有:
public class Table2 {
Integer[] data;
public Table2() {
data = new Integer[100];
}
访问 Table.data[0].data[0]
Table.data[0].data[0] is not null.
该程序在 Eclipse 中工作,但在 Eclipse 之外我收到 NoSuchField 错误。我不确定如何解决这个问题。
最佳答案
您在访问它的代码中一定犯了一些拼写错误/错误。如果您按如下方式执行,无论您在何处(eclipse或外部)访问它,结果都会相同。
public class Main {
public static void main(String[] args){
Table table=new Table();
table.data[0].data[0]=10;
System.out.println(table.data[0].data[0]);
}
}
输出:
10
关于java - 具有两个类的 Java 代码中的 NoSuchField 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59146208/