“无法找到符号”为我自己的类 [英] "Cannot find symbol" for my own class
问题描述
我没有设置%CLASSPATH%。正如我所理解的,这不应该是一个问题,因为Javac将假定当前目录的类路径。
I do not have a %CLASSPATH% set up. As I understand, this should not be a problem because Javac will assume a classpath of the current directory.
如下所示,javac无法找到我的 Case
类,即使它在同一个精确的目录。任何想法为什么这是发生?当我使用Eclipse时,此代码工作正常。
As you can see below, javac is unable to find my Case
class even though it's in the same exact directory. Any thoughts on why this is happening? This code works fine when I use Eclipse.
C:\Documents and Settings\joep\My Documents\GCJ\src\codejam2011\Round0\D>dir /B
Case.class
Case.java
EntryPoint.java
C:\Documents and Settings\joep\My Documents\GCJ\src\codejam2011\Round0\D>javac EntryPoint.java
EntryPoint.java:16: cannot find symbol
symbol : class Case
location: class codejam2011.Round0.D.EntryPoint
ArrayList<Case> cases = new ArrayList<Case>();
^
EntryPoint.java:16: cannot find symbol
symbol : class Case
location: class codejam2011.Round0.D.EntryPoint
ArrayList<Case> cases = new ArrayList<Case>();
^
EntryPoint.java:24: cannot find symbol
symbol : class Case
location: class codejam2011.Round0.D.EntryPoint
cases.add(new Case(new Integer(count), line));
^
3 errors
C:\Documents and Settings\joep\My Documents\GCJ\src\codejam2011\Round0\D>
更新1:
尝试从我的包根(src)编译之后,我得到一个新的错误(即使删除了Case.class文件)。
After trying to compile from my package root (src), I get a new error (even after deleting the Case.class file)
C:\Documents and Settings\joep\My Documents\GCJ\src>javac -cp . codejam2011/Round0/D/EntryPoint.java
codejam2011\Round0\D\EntryPoint.java:16: cannot access codejam2011.Round0.D.Case
bad class file: .\codejam2011\Round0\D\Case.java
file does not contain class codejam2011.Round0.D.Case
Please remove or make sure it appears in the correct subdirectory of the classpath.
ArrayList<Case> cases = new ArrayList<Case>();
^
1 error
C:\Documents and Settings\joep\My Documents\GCJ\src>
更新2:
看起来是抓取案例.java文件。
Update 2: It appears to be grabbing the Case.java file from a different package.
C:\Documents and Settings\joep\My Documents\GCJ\src>javac -d ../classes codejam2011\Round0\D\*.java
.\codejam2011\Round0\D\Case.java:4: duplicate class: codejam2011.Round0.C.Case
public class Case
^
codejam2011\Round0\D\EntryPoint.java:16: cannot access codejam2011.Round0.D.Case
bad class file: .\codejam2011\Round0\D\Case.java
file does not contain class codejam2011.Round0.D.Case
Please remove or make sure it appears in the correct subdirectory of the classpath.
ArrayList<Case> cases = new ArrayList<Case>();
^
2 errors
C:\Documents and Settings\joep\My Documents\GCJ\src>
推荐答案
您需要从包根内部包。
You need to compile from the package root, not from inside the package.
因此, cd
到 src
从那里。
javac -cp . codejam2011/Round0/D/EntryPoint.java
strong>更新:根据您的新问题,您需要以相同的方式重新编译 Case.java
。它显然编译相同的错误的方式(从包内)。
Update: as per your new problem, you need to recompile Case.java
the same way. It was apparently compiled the same wrong way (from inside the package).
这篇关于“无法找到符号”为我自己的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!