我没有设置%CLASSPATH%。据我所知,这不应该是一个问题,因为Javac会承担当前目录的类路径。“我找不到符号”我的班级
正如你在下面看到的,即使它在同一个确切的目录下,javac也无法找到我的Case
类。任何想法为什么发生这种情况?当我使用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:
尝试(即使删除Case.class文件后)
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>
从我的包根(SRC),我得到一个新的错误编译后更新2: 它似乎是从另一个包中获取Case.java文件。
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>
您是否在EntryPoint中导入class Case? – Danish 2011-05-13 21:43:33
@Danish:这是没有必要的,因为它在同一个包中。 – BalusC 2011-05-13 21:47:28
你学习了错误信息吗? '重复类:codejam2011.Round0.C.Case'有C和D - 含糊不清。你必须排除一些导入,或者明确地指定哪个Case,codejam2011.Round0.C.Case或codejam2011.Round0.D.Case的意思。 – 2011-05-13 22:25:03