简体   繁体   English

缺少 JavaFX 应用程序类

[英]Missing JavaFX application class

I have java code like this:我有这样的Java代码:

package mypackage;

import javafx.application.Application;
import javafx.stage.Stage;

public class MyApp extends Application{
    public static void main(String args[]){
        launch(args);
    }
    public void start(Stage primaryStage){
        primaryStage.show();
    }
}

and I've compiled it at ~/myjava/src/mypackage/MyApp.class .我在~/myjava/src/mypackage/MyApp.class编译了它。 then, when I'm running from然后,当我从

~$ java -cp myjava/src mypackage/MyApp

why getting error like:为什么会出现如下错误:

Missing JavaFX application class mypackage/MyApp

I'm using JDK 8.我正在使用 JDK 8。

That is because you are calling your application with a directory path instead of the fully qualified classname.那是因为您正在使用目录路径而不是完全限定的类名调用您的应用程序。 The fully qualified classname is composed from the package name and the class name.完全限定的类名由包名和类名组成。 In your case this is mypackage.MyApp .在您的情况下,这是mypackage.MyApp

Assuming that your compiled class resides in the same folder as the source .java file, call it this way:假设您编译的类与源.java文件位于同一文件夹中,请这样调用:

java -cp myjava/src mypackage.MyApp

After installing Java 15 and JavaFX 13 and some other changes I too was getting "Missing JavaFX application class mypackage/MyApp" and in my case the package name and application were correct.在安装 Java 15 和 JavaFX 13 以及其他一些更改后,我也收到了“缺少 JavaFX 应用程序类 mypackage/MyApp”的消息,在我的情况下,包名称和应用程序是正确的。 I was using some JDK15 preview functions and I needed the JVM option --enable-preview.我正在使用一些 JDK15 预览功能,我需要 JVM 选项 --enable-preview。 In desperation I started to change things, as this used to work.无奈之下,我开始改变事情,因为这曾经奏效。 When I removed the --enable-preview option I received error messages relating to the fact I was using preview functions and did not specify it.当我删除 --enable-preview 选项时,我收到了与我使用预览功能相关的错误消息,但没有指定它。 This told me the loader was in fact finding my application.这告诉我加载程序实际上正在查找我的应用程序。 The error message "Missing JavaFX application class mypackage/MyApp" was incorrect in this case.在这种情况下,错误消息“缺少 JavaFX 应用程序类 mypackage/MyApp”不正确。 The problem was I needed to include some user utility classes that MyApp was dependent upon.问题是我需要包含一些 MyApp 所依赖的用户实用程序类。 Once I included the dependent classes in the classpath all was well.一旦我在类路径中包含了依赖类,一切都很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM