“不能找到符号”编译错误 [英] "Cannot Find Symbol" compile error
问题描述
我的编码经验只有几年,所以这个问题应该很容易回答。
My coding experience has only gone back a few years, so this question should be easy enough to answer.
我写了两个界面:类和游戏。接口CLASS应该扩展接口GAME。
I have written two interfaces: Class and Game. Interface CLASS is supposed to extend interface GAME.
以下是两个接口源:
package Impl;
public interface Game
{
//METHODS AND VARS
}
package Impl;
public interface Class extends Game
{
//METHODS AND VARS
}
现在,当我尝试编译第二个界面时,会出现以下错误:
Now, when I try to compile the second interface, I get the following error
class.java:4: cannot find symbol
symbol: class Game
public interface Class extends Game
^
我的Game类被编译,类文件与两个java文件在同一个目录中。我没有能够找到一个解决方案。有人有任何想法吗?
My Game class is compiled and the class file is in the same directory as both java files. I have not been able to find a solution. Does anyone have any ideas?
推荐答案
类名区分大小写。您可能已经创建了一个名为 game
的接口,但是您在 Class
接口声明中将其称为 Game
,编译器找不到。
Class names are case sensitive. It is possible that you have created an interface called game
, but you refer to it in your Class
interface declaration as Game
, which the compiler cannot find.
但是,您还有另一种机会从您的 Impl
包中进行编译。为此,您需要引用类路径,以便编译器可以从包结构的基础中查找类。您可以在类名前添加 -classpath ..
arg到 javac
:
However, there is another chance that you are compiling from within your Impl
package. To do this, you will need to reference your classpath such that the compiler can find classes from the base of the package structure. You can add a -classpath ..
arg to your javac
before the class name:
javac -classpath .. Class.java
$ b b
或者,您可以做更常见的事情,从包结构的根目录进行编译。要这样做,您需要指定类
文件的路径:
javac Impl\Class.java
您可以随时添加 -classpath。
清楚。
这篇关于“不能找到符号”编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!