如何在11 Java JDK版本中解决此JavaFX问题?

时间:2018-12-23 23:57:14

标签: java javafx java-11 javafx-11 openjfx

我目前在“ Intellij IDEA Edition 2018.3.1”中遇到一个奇怪的问题,当我运行JavaFX程序时,总是会抛出一个错误。只是因为我添加了几行代码。

错误:

"C:\Program Files\Java\jdk-11.0.1\bin\java.exe" --add-modules javafx.base,javafx.graphics --add-reads javafx.base=ALL-UNNAMED --add-reads javafx.graphics=ALL-UNNAMED "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.3.1\lib\idea_rt.jar=19311:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.3.1\bin" -Dfile.encoding=UTF-8 -p "C:\Users\User\Desktop\JAVAFX 11\javafx-sdk-11.0.1\lib\javafx.base.jar;C:\Users\User\Desktop\JAVAFX 11\javafx-sdk-11.0.1\lib\javafx.graphics.jar;C:\Users\User\Desktop\DEVELOPMENT\JAVA 11 FX\Propertys\bin;C:\Users\User\Desktop\JAVAFX 11\javafx-sdk-11.0.1\lib\javafx-swt.jar;C:\Users\User\Desktop\JAVAFX 11\javafx-sdk-11.0.1\lib\javafx.controls.jar;C:\Users\User\Desktop\JAVAFX 11\javafx-sdk-11.0.1\lib\javafx.fxml.jar;C:\Users\User\Desktop\JAVAFX 11\javafx-sdk-11.0.1\lib\javafx.media.jar;C:\Users\User\Desktop\JAVAFX 11\javafx-sdk-11.0.1\lib\javafx.swing.jar;C:\Users\User\Desktop\JAVAFX 11\javafx-sdk-11.0.1\lib\javafx.web.jar" -m Propertys/application.Main
Exception in Application start method
java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NullPointerException: Input stream must not be null
    at javafx.graphics/javafx.scene.image.Image.validateInputStream(Image.java:1117)
    at javafx.graphics/javafx.scene.image.Image.<init>(Image.java:701)
    at Propertys/application.Main.start(Main.java:114)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    ... 1 more
Exception running application application.Main

Process finished with exit code 1
Button bt1 = new Button("B E E N D E N");
Image image = new Image(getClass().getResourceAsStream("src/Download.png"));
bt1.setGraphic(new ImageView(image));
root.getChildren().add(bt1);

尽管在IDE中没有显示错误。

我还创建了一个“ module-file.java”文件,并插入了所有组件以制作JavaFX程序。

我什至将全局库添加到模块和这些文件中:

https://imgur.com/a/WsMt2j8

感谢您的每一个回答。

1 个答案:

答案 0 :(得分:1)

您的输入流为空,因为所需的资源不在 classpath 中的“ src / Download.png”(不是文件系统)

改为使用“ /Download.png”