问题描述
我没有设置 %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 SettingsjoepMy DocumentsGCJsrccodejam2011Round0D>dir /B
Case.class
Case.java
EntryPoint.java
C:Documents and SettingsjoepMy DocumentsGCJsrccodejam2011Round0D>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 SettingsjoepMy DocumentsGCJsrccodejam2011Round0D>
更新 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 SettingsjoepMy DocumentsGCJsrc>javac -cp . codejam2011/Round0/D/EntryPoint.java
codejam2011Round0DEntryPoint.java:16: cannot access codejam2011.Round0.D.Case
bad class file: .codejam2011Round0DCase.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 SettingsjoepMy DocumentsGCJsrc>
更新 2:它似乎是从不同的包中获取 Case.java 文件.
Update 2:It appears to be grabbing the Case.java file from a different package.
C:Documents and SettingsjoepMy DocumentsGCJsrc>javac -d ../classes codejam2011Round0D*.java
.codejam2011Round0DCase.java:4: duplicate class: codejam2011.Round0.C.Case
public class Case
^
codejam2011Round0DEntryPoint.java:16: cannot access codejam2011.Round0.D.Case
bad class file: .codejam2011Round0DCase.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 SettingsjoepMy DocumentsGCJsrc>
推荐答案
您需要从包根目录进行编译,而不是从包内部进行编译.
You need to compile from the package root, not from inside the package.
所以,cd
到 src
文件夹并从那里编译.
So, cd
to the src
folder and compile from there.
javac -cp . codejam2011/Round0/D/EntryPoint.java
更新:根据您的新问题,您需要以相同的方式重新编译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).
这篇关于“找不到符号"为我自己的班级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!