[英]java.lang.NoClassDefFoundError when running with cmd
I have some problems testing a program from a java programming book. 我在测试Java编程书中的程序时遇到一些问题。 I wrote the code in eclipse and succeded running it, but when I compile the .java
file via the command line and then run it with java ConsoleEcho
, I get this error: 我用eclipse编写了代码,并成功运行了它,但是当我通过命令行编译.java
文件,然后使用java ConsoleEcho
运行它时,出现此错误:
Exception in thread "main" java.lang.NoClassDefFoundError: ConsoleEcho (wrong na
me: einausgabe/ConsoleEcho)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:792)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:14
2)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
The code for my program is: 我程序的代码是:
package einausgabe;
import java.io.IOException;
import static java.lang.System.*;
public class ConsoleEcho {
public static void main( String args[] ) throws IOException {
while( true ) {
int code = in.read();
out.write(code);
}
}
}
The commands I used are: 我使用的命令是:
javac ConsoleEcho
java ConsoleEcho
I run this from the directory ..\\Java\\ProgrammierenMitJava2\\src\\einausgabe
我从目录..\\Java\\ProgrammierenMitJava2\\src\\einausgabe
I don't get any errors by compiling. 我没有通过编译得到任何错误。 Tried java einausgabe.ConsoleEcho
and then I get this error message: 尝试过java einausgabe.ConsoleEcho
,然后收到此错误消息:
Error: Could not find or load main class einausgabe.ConsoleEcho
You need to include the package name in the command line, something like: 您需要在命令行中包含软件包名称,例如:
java einausgabe.ConsoleEcho
you appear to just have the class name in your command. 您似乎在命令中只有类名。
It seems that you forgot the package name 您似乎忘记了包裹名称
Use 采用
java einausgabe.ConsoleEcho
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.