简体   繁体   中英

Missing JavaFX application class

I have java code like this:

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 . 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.

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 .

Assuming that your compiled class resides in the same folder as the source .java file, call it this way:

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. I was using some JDK15 preview functions and I needed the JVM option --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. 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. The problem was I needed to include some user utility classes that MyApp was dependent upon. Once I included the dependent classes in the classpath all was well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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