我得到了两个 java 文件(主类(Practica1)和另一个类(Matriz2x2))。两者都在同一个文件夹中。主类实例化了我获得的类,这就是“找不到符号”错误弹出的地方。类 Matriz2x2 编译。
我不会给出每个类(方法等)的详细信息,所以简单来说,Matriz2x2 类是这样的:
package mx.unam.ciencias.icc;
public class Matriz2x2 {
private double a;
private double b;
private double c;
private double d;
public Matriz2x2(double a, double b,
double c, double d) {
this.a = a;
this.b = b;
this.c = c;
this.d = d;
}
}
这是主要课程:
package mx.unam.ciencias.icc;
import java.util.Random;
public class Practica1 {
public static void main(String[] args) {
Random r = new Random();
Matriz2x2 m = new Matriz2x2(r.nextDouble() * 100,
r.nextDouble() * 100,
r.nextDouble() * 100,
r.nextDouble() * 100);
}
}
这是发脾气:
jose@jose-ThinkPad-T420:~/practica1/src/mx/unam/ciencias/icc$ javac Practica1.java
Practica1.java:13: cannot find symbol
symbol : class Matriz2x2
location: class mx.unam.ciencias.icc.Practica1
Matriz2x2 m = new Matriz2x2(r.nextDouble() * 100,
^
Practica1.java:13: cannot find symbol
symbol : class Matriz2x2
location: class mx.unam.ciencias.icc.Practica1
Matriz2x2 m = new Matriz2x2(r.nextDouble() * 100,
^
Practica1.java:17: cannot find symbol
symbol : class Matriz2x2
location: class mx.unam.ciencias.icc.Practica1
Matriz2x2 n = new Matriz2x2(r.nextDouble() * 100,
^
Practica1.java:17: cannot find symbol
symbol : class Matriz2x2
location: class mx.unam.ciencias.icc.Practica1
Matriz2x2 n = new Matriz2x2(r.nextDouble() * 100,
^
Practica1.java:37: cannot find symbol
symbol : class Matriz2x2
location: class mx.unam.ciencias.icc.Practica1
Matriz2x2 i = m.inversa();
^
Practica1.java:43: cannot find symbol
symbol : class Matriz2x2
location: class mx.unam.ciencias.icc.Practica1
Matriz2x2 id = m.multiplica(i);
^
6 errors
正如您所看到的,关于我没有包含在 Matriz2x2 示例中的方法还有其他错误,但我没有,因为它们都是关于同一个问题,它只是找不到 Matriz2x2 类。这可能很简单,但我只是没有看到他们可能在代码中写的任何错误(除了老师写的)所以我不明白为什么主类没有编译,一切似乎都是正确的。