简体   繁体   English

错误:无法找到或加载主 class (java.lang.NoClassDefFoundError) Ubuntu 18.04

[英]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.

相关问题 java.lang.NoClassDefFoundError / 无法找到或加载主类 - java.lang.NoClassDefFoundError / Could not find or load main class 错误:无法找到或加载主类 application.Main 导致:java.lang.NoClassDefFoundError:javafx/application/Application JDK 11 - Error: Could not find or load main class application.Main Caused by: java.lang.NoClassDefFoundError: javafx/application/Application JDK 11 错误:找不到或加载主类 Game.GUI.Start 原因:java.lang.NoClassDefFoundError:javafx/application/Application - Error: Could not find or load main class Game.GUI.Start Caused by: java.lang.NoClassDefFoundError: javafx/application/Application java.lang.NoClassDefFoundError:无法初始化类 - java.lang.NoClassDefFoundError: Could not initialize class java.lang.NoClassDefFoundError:无法初始化类 - java.lang.NoClassDefFoundError: Could not initialize class Ubuntu Java -jar错误:找不到或加载主类 - Ubuntu Java -jar error: Could not find or load main class java.lang.NoClassDefFoundError 找不到类 - java.lang.NoClassDefFoundError Cannot Find CLASS 线程“main”中的异常java.lang.NoClassDefFoundError:无法初始化类org.springframework.jdbc.core.StatementCreatorUtils - Exception in thread “main” java.lang.NoClassDefFoundError: Could not initialize class org.springframework.jdbc.core.StatementCreatorUtils 线程“ main”中的异常java.lang.NoClassDefFoundError无法初始化类org.bytedeco.javacpp.avutil - Exception in thread “main” java.lang.NoClassDefFoundError Could not initialize class org.bytedeco.javacpp.avutil 线程“主”java.lang.NoClassDefFoundError 中的异常:无法初始化 class sun.util.calendar.ZoneInfoFile - Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class sun.util.calendar.ZoneInfoFile
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM