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.
我没有设置%CLASSPATH%。正如我所理解的,这不是问题,因为Javac将假定当前目录的类路径。
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.
正如您可以看到的,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>
Update 1:
更新1:
After trying to compile from my package root (src), I get a new error (even after deleting the Case.class file)
在尝试从我的包根(src)编译后,我得到了一个新的错误(即使删除了这个例子)。类文件)
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>
Update 2: It appears to be grabbing the Case.java file from a different package.
更新2:它似乎正在抓住这个案子。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>
4 个解决方案
#1
18
You need to compile from the package root, not from inside the package.
您需要从包根编译,而不是从包内部编译。
So, cd
to the src
folder and compile from there.
因此,cd到src文件夹并从那里编译。
javac -cp . codejam2011/Round0/D/EntryPoint.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).
更新:根据您的新问题,您需要重新编译案例。java相同的方式。显然,它是用同样的错误方式编译的(从包内部)。
#2
1
If the problem is not yet solved by compiling from the package root directory (see the other answers):
如果从包根目录中编译,问题还没有得到解决(参见其他答案):
- make sure all the source files contain classes with names corresponding to their file name
- 确保所有源文件都包含与文件名对应的类。
- make sure all the source files contain a package statement corresponding to their position in the source file hierarchy
- 确保所有源文件都包含与源文件层次结构中的位置相对应的包语句。
- delete all your .class files before compiling (this should only be necessary once, if you checked everything else).
- 在编译之前删除所有的.class文件(如果您检查了其他内容,这应该只需要一次)。
Thus, if the file is codejam2011\Round0\D\Case.java
, it should contain package codejam2011.Round0.D;
as the first declaration, and then public class Case { ... }
. Also, make sure there is no other source file containing this package and class declaration.
因此,如果该文件是codejam2011\Round0\D\Case。java,它应该包含package codejam2011.Round0.D;作为第一个声明,然后是public class Case{…}。另外,请确保没有包含此包和类声明的其他源文件。
From your error message, it looks like the package statement is package codejam2011.Round0.C;
instead (and you also have a class Case
in the real codejam2011.Round0.C
package).
从您的错误消息来看,它看起来像包语句是package codejam2011.Round0.C;相反,在真正的codejam2011.Round0中也有一个类的例子。C包)。
#3
0
You are in the wrong directory for compiling.
您在错误的目录中进行编译。
location: class codejam2011.Round0.D.EntryPoint
That tells me, that your package is codejam2011.Round0.D (which is against the convention (all lowercase) but beside the point ...
这告诉我,您的包是codejam2011.Round0。D(这是违反惯例的(都是小写的),但在这一点上……
cd to the parent dir of codejam2011, which is src, isn't it?
cd到codejam2011的父目录,它是src,不是吗?
javac codejam2011\Round0\D\EntryPoint.java
might do the trick.
的一招。
Often you have a directory for compiled classes, like 'bin' or 'classes'. To produce the classes there, use -d (destination):
通常,您有一个编译类的目录,比如“bin”或“classes”。使用-d(目的地)在那里生成类:
javac -d ../classes codejam2011\Round0\D\EntryPoint.java
#4
-1
I have similar issue, it might not apply to all cases, but what I have done is remove .gradle, build and out folder and rebuild the program again.
我有类似的问题,可能不适用于所有的情况,但是我所做的是删除。gradle, build和out文件夹并重新构建程序。
#1
18
You need to compile from the package root, not from inside the package.
您需要从包根编译,而不是从包内部编译。
So, cd
to the src
folder and compile from there.
因此,cd到src文件夹并从那里编译。
javac -cp . codejam2011/Round0/D/EntryPoint.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).
更新:根据您的新问题,您需要重新编译案例。java相同的方式。显然,它是用同样的错误方式编译的(从包内部)。
#2
1
If the problem is not yet solved by compiling from the package root directory (see the other answers):
如果从包根目录中编译,问题还没有得到解决(参见其他答案):
- make sure all the source files contain classes with names corresponding to their file name
- 确保所有源文件都包含与文件名对应的类。
- make sure all the source files contain a package statement corresponding to their position in the source file hierarchy
- 确保所有源文件都包含与源文件层次结构中的位置相对应的包语句。
- delete all your .class files before compiling (this should only be necessary once, if you checked everything else).
- 在编译之前删除所有的.class文件(如果您检查了其他内容,这应该只需要一次)。
Thus, if the file is codejam2011\Round0\D\Case.java
, it should contain package codejam2011.Round0.D;
as the first declaration, and then public class Case { ... }
. Also, make sure there is no other source file containing this package and class declaration.
因此,如果该文件是codejam2011\Round0\D\Case。java,它应该包含package codejam2011.Round0.D;作为第一个声明,然后是public class Case{…}。另外,请确保没有包含此包和类声明的其他源文件。
From your error message, it looks like the package statement is package codejam2011.Round0.C;
instead (and you also have a class Case
in the real codejam2011.Round0.C
package).
从您的错误消息来看,它看起来像包语句是package codejam2011.Round0.C;相反,在真正的codejam2011.Round0中也有一个类的例子。C包)。
#3
0
You are in the wrong directory for compiling.
您在错误的目录中进行编译。
location: class codejam2011.Round0.D.EntryPoint
That tells me, that your package is codejam2011.Round0.D (which is against the convention (all lowercase) but beside the point ...
这告诉我,您的包是codejam2011.Round0。D(这是违反惯例的(都是小写的),但在这一点上……
cd to the parent dir of codejam2011, which is src, isn't it?
cd到codejam2011的父目录,它是src,不是吗?
javac codejam2011\Round0\D\EntryPoint.java
might do the trick.
的一招。
Often you have a directory for compiled classes, like 'bin' or 'classes'. To produce the classes there, use -d (destination):
通常,您有一个编译类的目录,比如“bin”或“classes”。使用-d(目的地)在那里生成类:
javac -d ../classes codejam2011\Round0\D\EntryPoint.java
#4
-1
I have similar issue, it might not apply to all cases, but what I have done is remove .gradle, build and out folder and rebuild the program again.
我有类似的问题,可能不适用于所有的情况,但是我所做的是删除。gradle, build和out文件夹并重新构建程序。