[英]Error: Could not find or load main class (java.lang.NoClassDefFoundError) Ubuntu 18.04
Using the ls commmand, I can clearly see both the.java file and the.class file of my main class created from compilation.使用 ls 命令,我可以清楚地看到编译创建的主 class 文件的 .java 文件和 .class 文件。 However, when I try to run it, the Ubuntu terminal says that the class was not found.
但是,当我尝试运行它时,Ubuntu 终端说没有找到 class。 Here's a screenshot of my terminal
这是我的终端的屏幕截图
And here's a snippet of my main class这是我的主要 class 的片段
Any answers?有什么答案吗?
You haved a class inside package.您在 package 中有一个 class。 So you should run your class in /home/se folder and use command java cs3421_emul.cs3421_emul
因此,您应该在 /home/se 文件夹中运行 class 并使用命令 java cs3421_emul.cs3421_emul
Since your classes are in a package your compiled classes should in the proper folder structure.由于您的类位于 package 中,因此您编译的类应位于正确的文件夹结构中。
To compile the classes to proper package folders use -d.
要将类编译为正确的 package 文件夹,请使用
-d.
switch while compiling.编译时切换。
javac -d . *.java
The above command will create folders based on the package of the classes.上述命令将根据类的 package 创建文件夹。 for example you
class3421_emul
has a package class3421_emul
so it will be compiled to class3421_emul
folder.例如,您的
class3421_emul
有一个 package class3421_emul
,因此它将被编译到class3421_emul
文件夹。
Then run the class using java class3421_emul.class3421_emul
然后使用
java class3421_emul.class3421_emul
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.