java:无法解析符号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1563112/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java : cannot resolve symbol
提问by vas
I was compiling an JAVA ( 1.4 varsion )file and was getting the following error (about 100 times all are same).
我正在编译一个 JAVA ( 1.4 varsion ) 文件并收到以下错误(大约 100 次都是相同的)。
Appli.java:721: cannot resolve symbol
symbol : class License
location: class test.App.Appli
License sellLicense = sell.getLicense();
I used
我用了
run/cmd/cd D:...../javac Appli.java
I had set the CLASSPATH variable, to the Classes folder of the java files I am presently running.
我已将 CLASSPATH 变量设置为我目前正在运行的 java 文件的 Classes 文件夹。
Control panel/Settings/System/System Properties /Advanced/Environmental Variables/System Variables/ Add/CLASSPATH
Should I use
我应该使用
How to solve the issue?
如何解决问题?
回答by aperkins
It looks to me like you need to compile the class License with the class Appli. Take a look at the Javac Documentationfor more details, but you can do something like the following:
在我看来,您需要使用类 Appli 编译类许可证。查看Javac 文档了解更多详细信息,但您可以执行以下操作:
javac Appli.java License.java
If License is in a library, you will need to add the library to your compilation classpath. This is done with the -classpath flag:
如果 License 在库中,则需要将该库添加到编译类路径中。这是通过 -classpath 标志完成的:
javac -classpath "classpath" Appli.java
回答by Stephen C
You need to set the CLASSPATH and make sure that you are in the correct directory.
您需要设置 CLASSPATH 并确保您位于正确的目录中。
Assuming that test.App.Applis trying to reference test.App.License, the directory structure should be:
假设test.App.Appl正在尝试引用test.App.License,目录结构应该是:
/somedir/test
/somedir/test/App
/somedir/test/App/Appl.java
/somedir/test/App/License.java
You should set $CLASSPATHto "/somedir", then change your current directory to /somedirand run the compiler as javac test/App/*.java; e.g.
您应该设置$CLASSPATH为"/somedir",然后将当前目录更改为/somedir并运行编译器javac test/App/*.java;例如
$ export CLASSPATH="/somedir"
$ cd /somedir
$ javac test/App/*.java
You can also use the -cpcommand line option with the javac(and later the java) command, and you run the javaccompiler from a different directory by using the -sourcepathoption.
您还可以将-cp命令行选项与javac(以及稍后的java)命令一起使用,并javac使用该-sourcepath选项从不同的目录运行编译器。
The other possibility is that the package for Licenseis not test.App. If that is the case, you need to adjust the directory structure to match the package naming, and add an importstatement to the Applclass.
另一种可能性是包License不是test.App。如果是这种情况,您需要调整目录结构以匹配包命名,并import在Appl类中添加一条语句。
EDIT: If you notice a build.xmlor pom.xml(or possibly even a Makefile) in the source tree, you probably should not be using javacdirectly. A build.xmlis for building using Ant, a 'pom.xmlis for Maven (or Ivy) and aMakefileormakefileis formake`.
编辑:如果您注意到源树中的abuild.xml或pom.xml(甚至可能是 a Makefile),您可能不应该javac直接使用。Abuild.xml用于构建 using Ant,一个“pom.xml is for Maven (or Ivy) and aMakefile ormakefile is formake”。
回答by jjnguy
You are probably missing an importstatement.
您可能遗漏了一个import声明。

