[英]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$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 程序。
我什至將全局庫添加到模塊和這些文件中:
我要感謝你的每一個回答。
您的輸入流為空,因為您想要的資源不在類路徑中的“src/Download.png”(不是文件系統)
改用“/Download.png”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.