[英]Where does this compiling error come from?
I am getting quite frustrated right now, and the main source of my frustration is the following error: 我现在很沮丧,而导致沮丧的主要原因是以下错误:
LogicalAutomaton.java:16: error: cannot find symbol
Cellular[i][j] = new Cellular (null, Cellular[i+1][j], null, Cellular[i][j+1]);
^
symbol: variable Cellular
location: class LogicalAutomaton
The class hierarchy is the following: 类层次结构如下:
home --> code --> Automata --> automata
And here is the code: 这是代码:
This is the class Cellular.java, in home/code/Automata/automata: 这是Home / code / Automata / automata中的Cellular.java类:
package automata;
public class Cellular {
private int state;
private Cellular upper, lower, left, right;
public Cellular (Cellular upper, Cellular lower, Cellular left,Cellular right) {
this.state = 0;
this.upper = upper;
this.lower = lower;
this.left = left;
this.right = right;
}
}
And this is the class LogicalAutomaton.java, in home/code/Automata: 这是home / code / Automata中的类LogicalAutomaton.java:
import automata.Cellular;
import java.util.Arrays;
public class LogicalAutomaton extends Cellular {
public static void main (String[] args) {
int n = 3;
Cellular[][] a = new Cellular[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == 0) {
if (j == 0) {
Cellular[i][j] = new Cellular (null, Cellular[i+1][j], null, Cellular[i][j+1]);
}
else {
if (j == n-1) {
Cellular[i][j] = new Cellular (null, Cellular[i+1][j], Cellular[i][j-1], null);
}
else {
Cellular[i][j] = new Cellular (null, Cellular[i+1][j], Cellular[i][j-1], Cellular[i][j+1]);
}
}
}
}
}
}
}
The code of LogicalAutomaton.java is much longer, but the main idea is to get access to the array of Cellular objects in order to initialize them, and each time I try to do this, it throws me said error. LogicalAutomaton.java的代码更长,但主要思想是访问Cellular对象数组以对其进行初始化,并且每次尝试执行此操作时,都会抛出错误。 Funnily enough, the compiler does not lament the declaration of the Cellular array.
有趣的是,编译器不会为Cellular数组的声明感到遗憾。
Do you have any idea where I might have done wrong? 您知道我做错了什么吗?
Thank you in advance! 先感谢您!
Edit: 编辑:
Sorry for the clumsy question; 很抱歉这个笨拙的问题; here is part of the faulty code.
这是错误代码的一部分。
You define your array as 您将数组定义为
Cellular[][] a = new Cellular[n][n];
but then later on, you use 但后来,您使用
Cellular[i][j] = new Cellular (null, Cellular[i+1][j], null, Cellular[i][j+1]);
when in fact, you should be using 实际上,您应该使用
a[i][j] = new Cellular (null, Cellular[i+1][j], null, Cellular[i][j+1]);
The error message you are getting 您收到的错误消息
LogicalAutomaton.java:16: error: cannot find symbol Cellular[i][j] = new Cellular (null, Cellular[i+1][j], null, Cellular[i][j+1]);
LogicalAutomaton.java:16:错误:找不到符号Cellular [i] [j] =新的Cellular(null,Cellular [i + 1] [j],null,Cellular [i] [j + 1]); ^ symbol: variable Cellular location: class LogicalAutomaton
^符号:变量单元格位置:类LogicalAutomaton
is saying I cannot find a variable named Cellular, not that I cannot find the class. 是说我找不到名为Cellular的变量,而不是找不到类。 This is because you have not defined a variable called Cellular , the variable you have defined is called a .
这是因为您尚未定义一个名为Cellular的变量,所以您定义的变量称为a 。
This problem is because of accessibility. 此问题是由于可访问性。 The
Cellular
class is not accessible in the LogicalAutomoton
class. 该
Cellular
类是不是在访问LogicalAutomoton
类。 Check your CLASSPATH variable and check whether the import statement is correct. 检查您的CLASSPATH变量,并检查import语句是否正确。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.