[英]How can I fix this JavaFX problem in the 11 Java JDK version?
I currently have a weird problem in " Intellij IDEA Edition 2018.3.1 " and when I run my JavaFX program I always get thrown out an error.我目前在“ Intellij IDEA Edition 2018.3.1 ”中有一个奇怪的问题,当我运行我的 JavaFX 程序时,我总是抛出一个错误。 Just because I added a few lines of code.
只是因为我添加了几行代码。
The error:错误:
"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);
Although no error is displayed in the IDE.虽然在IDE中没有显示错误。
I have also created a " module-file.java " file and inserted all components to make JavaFX programs.我还创建了一个“module-file.java”文件并插入了所有组件来制作 JavaFX 程序。
I've even added the global libraries to modules and these files:我什至将全局库添加到模块和这些文件中:
https://imgur.com/a/WsMt2j8 https://imgur.com/a/WsMt2j8
I would like to thank you for every answer.我要感谢你的每一个回答。
Your input stream is null because the resource you want is not located at "src/Download.png" in the classpath (NOT the file system)您的输入流为空,因为您想要的资源不在类路径中的“src/Download.png”(不是文件系统)
Use “/Download.png” instead改用“/Download.png”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.