[英]Using JavaFX with packages generates “Missing JavaFX application class” error
I'm working on getting started with JavaFX now that it comes with Java 8 and I've run into a strange issue. 我正在努力开始使用JavaFX,因为它带有Java 8,我遇到了一个奇怪的问题。 When running from the default package, my simple Hello World application runs just fine. 从默认包运行时,我的简单Hello World应用程序运行正常。 However, when putting it into a package, trying to run the program gives me the following error: 但是,当将它放入包中时,尝试运行该程序会给我以下错误:
Missing JavaFX application class view/JFXHelloWorld
I've included a normal HelloWorld.java
file in the view
folder and it works just fine. 我在view
文件夹中包含了一个普通的HelloWorld.java
文件,它工作得很好。
To clarify, my file structure looks like this: 为了澄清,我的文件结构如下所示:
jfx ----src --------view ------------HelloWorld.java ------------JFXHelloWorld.java ----target --------view ------------HelloWorld.class ------------JFXHelloWorld.class
Where target is the folder that I am putting the compiled files into with the following command: target是我使用以下命令将编译文件放入的文件夹:
javac -d target src/view/*.java
Running the normal HelloWorld.java file works just fine: 运行正常的HelloWorld.java文件可以正常工作:
java -cp target view/HelloWorld Hello, World!
However, running the JavaFX file causes a problem with the ClassLoader: 但是,运行JavaFX文件会导致ClassLoader出现问题:
java -cp target view/JFXHelloWorld Missing JavaFX application class view/JFXHelloWorld
Googling led me to 9 results, all of which are the source code for the JavaFX ClassLoader . 谷歌搜索引领我9个结果,所有这些都是JavaFX ClassLoader的源代码。
Both HelloWorld.java and JFXHelloWorld.java are declared to be in package view;
HelloWorld.java和JFXHelloWorld.java都声明在package view;
- is this correct? - 它是否正确? Any help would be appreciated. 任何帮助,将不胜感激。
My problem actually was in the command-line call to run HelloWorld. 我的问题实际上是在命令行调用中运行HelloWorld。
I should instead be calling the following: 我应该调用以下内容:
java -cp target view.HelloWorld
java -cp target view.JFXHelloWorld
For some reason, it allows you to run view/HelloWorld
when it shouldn't. 出于某种原因,它允许您在不应该运行view/HelloWorld
时运行它。
Maybe, your problem it's that JFXHelloWorld it's extending from Application and you aren't setting the classpath correctly. 也许,你的问题是JFXHelloWorld从应用程序扩展而你没有正确设置类路径。 Are you using Java8 or any previous Java release? 您使用的是Java8还是之前的Java版本?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.