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

How can I fix this JavaFX problem in the 11 Java JDK version?

我目前在“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(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(LauncherImpl.java:846)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait(PlatformImpl.java:455)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater(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(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

感谢您的每一个回答。

您的输入流为空,因为您需要的资源不在 类路径(不是文件系统)

中的 "src/Download.png"

改用“/Download.png”