本文介绍了缺少JavaFX应用程序类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的Java代码:
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();
}
}
,我已经在~/myjava/src/mypackage/MyApp.class
对其进行了编译.然后,当我从
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
我正在使用JDK 8.
I'm using JDK 8.
推荐答案
这是因为您使用目录路径而不是完全限定的类名来调用应用程序.完全限定的类名由包名和类名组成.您的情况是mypackage.MyApp
.
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
.
假定编译的类与源.java
文件位于同一文件夹中,请按以下方式调用它:
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
这篇关于缺少JavaFX应用程序类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!