我沒有設置%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