[英]Why am I getting error: cannot find symbol in java?
Error Messages [1]: https://i.stack.imgur.com/6Jfk1.jpg [2]: https://i.stack.imgur.com/MfX4T.jpg [3]: https://i.stack.imgur.com/4R6n3.jpg错误消息 [1]: https://i.stack.imgur.com/6Jfk1.jpg [2]: https://i.stack.imgur.com/MfX4T.jpg [3]: https://i.stack.imgur.com/MfX4T.jpg [3]: Z5E056C500A1C4BADE5Z://i.stack.imgur.com/MfX4T.jpg [3]: Z5E056C500AD8044 stack.imgur.com/4R6n3.jpg
I ran these two programs on my laptop and it ran fine.我在笔记本电脑上运行了这两个程序,运行良好。 I decided to download it and send it to my computer but now I am getting an error message.
我决定下载它并将其发送到我的计算机,但现在我收到一条错误消息。 I saved both programs in the same file and they are the same version of JGrasp.
我将这两个程序保存在同一个文件中,它们是相同版本的 JGrasp。 Any ideas on why this is happening?
关于为什么会发生这种情况的任何想法? Should I be importing the class before using it?
我应该在使用之前导入 class 吗?
To use the type Die
you need to define the type Die
in a file called Die.java
which contains要使用类型
Die
,您需要在名为Die.java
的文件中定义类型Die
,其中包含
public class Die {
... and some stuff here ...
}
In java you cannot use a type until it is created with some sort of "class " statement, and if that type is in a different package, then you need to import it with the line在 java 中,在使用某种“类”语句创建类型之前,您不能使用类型,如果该类型位于不同的 package 中,则需要使用该行导入它
import some.other.package.Die;
Your class is called PairOfDice
, while you're trying to instanciate an object of the Die
class.您的 class 称为
PairOfDice
,而您正在尝试实例化Die
class 的 object 。 Die
is only a method of the class mentioned before. Die
只是前面提到的class的一种方法。 You'll need to instanciate your die like this:你需要像这样实例化你的 die:
PairOfDice die1 = new PairOfDice();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.