错误:找不到或加载主类应用程序.主JAVAFX [英] Error: Could not find or load main class application.Main JAVAFX
问题描述
在我的项目属性下的Java Build Path Libraries下,我在Modulepath下有一个名为javafx12的用户库.
Under Java Build Path Libraries under the properties of my project, I have my User Library called javafx12 under Modulepath.
这删除了与导入javafx有关的所有错误,但未解决.
This removed all the errors regarding import javafx not resolved.
当我尝试运行我的项目时,我得到
When I try to run my project, I get
错误:无法找到或加载主类应用程序. 由以下原因引起:java.lang.NoClassDefFoundError:javafx/application/Application"
"Error: Could not find or load main class application.Main Caused by: java.lang.NoClassDefFoundError: javafx/application/Application"
如何摆脱这个错误?
我正在使用Java SE 12或JDK 12.
I am using Java SE 12 aka JDK 12.
我也在使用eclipse.
I am using eclipse as well.
package application;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
BorderPane root = new BorderPane();
Scene scene = new Scene(root,400,400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
类文件中没有错误.
推荐答案
在@Ashish链接openjfx.io/openjfx-docs
Following @Ashish link openjfx.io/openjfx-docs
我执行了以下操作,并修复了该错误:
I did the following and it fixed the error:
- 添加VM参数
要解决该问题,请单击运行->运行配置...-> Java应用程序,为名为
hellofx
的项目创建一个新的启动配置,并添加以下VM参数:
- Add VM arguments
To solve the issue, click on Run -> Run Configurations... -> Java Application, create a new launch configuration for your project named
hellofx
and add these VM arguments:
Linux/Mac Windows
Linux/Mac Windows
-模块路径"\ path \ to \ javafx-sdk-12.0.1 \ lib" --add-modules javafx.controls,javafx.fxml 警告:请确保以下选项:
--module-path "\path\to\javafx-sdk-12.0.1\lib" --add-modules javafx.controls,javafx.fxml Warning: Make sure the option:
在使用SWT启动时使用-XstartOnFirstThread参数 未选择. VM参数单击应用",然后关闭对话框.
Use the -XstartOnFirstThread argument when launching with SWT is not selected. VM arguments Click apply and close the dialog.
这篇关于错误:找不到或加载主类应用程序.主JAVAFX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!