-2

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. 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.

I have also created a " module-file.java " file and inserted all components to make JavaFX programs.

I've even added the global libraries to modules and these files:

https://i.stack.imgur.com/R3fhV.jpg

I would like to thank you for every answer.

Naman
  • 27,789
  • 26
  • 218
  • 353
  • Why not place the resources under the `resources` folder instead? Also, try and map resources to a path similar to packages constructed to access them in the java `src` folder. – Naman Dec 24 '18 at 02:27

1 Answers1

1

Your input stream is null because the resource you want is not located at "src/Download.png" in the classpath (NOT the file system)

Use “/Download.png” instead

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
  • Though its IntelliJ that the OP is using, yet probably could be for the reason that the way of accessing the resources has been updated in Java9 and above. For that reason, the path specified is incorrect and not resolving the inputstream. Details in the [javadoc](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Class.html#getResourceAsStream(java.lang.String)) and further in the JDK code. – Naman Dec 24 '18 at 02:28
  • 1
    I missed that part of the question. I have only seen the "src/" layout in Eclipse. However, I have only used IntelliJ with Maven projects so they may use the same in their default Java project template. – Thorbjørn Ravn Andersen Dec 24 '18 at 04:21
  • @nullpointer hmm ... don't see much of a change when it comes to lookup paths (getting them wrong somehow always are the most probable cause of problems) except for keeping the module constraints in mind as well. – kleopatra Dec 24 '18 at 11:28
  • @nullpointer To my understanding this has not changed in Java 9+ but the system is not very helpful if you get this wrong. Here we have both a relative path and a confusion between the file system names and the resulting classpath. – Thorbjørn Ravn Andersen Dec 25 '18 at 14:55
  • @ThorbjørnRavnAndersen Agreed over the part that accessing incorrect resource path would anyway result in failure. Though I wasn't very sure if the Java-11 tag meant that the existing code in JDK8 or lower worked fine for OP. Your solution is anyway something I would rely on. Yet the structure that the OP is using, IMHO would definitely cause further issues if not corrected otherwise... and nevertheless the question isn't very clear either to specify all these details in discussion. – Naman Dec 25 '18 at 14:59