0

So, I am trying to use a css file in JavaFX for the first time. Here is my code, error and file location:

scene.getStylesheets().add("C:/Users/myUser/IdeaProjects/CupOfTea/src/main/resources//main.css");

enter image description here

>! Exception in Application start method
>! java.lang.reflect.InvocationTargetException
>!  at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
>!  at java.base/java.lang.reflect.Method.invoke(Method.java:578)
>!  at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:465)
>!  at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:364)
>!  at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
>!  at java.base/java.lang.reflect.Method.invoke(Method.java:578)
>!  at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1081)
>! Caused by: java.lang.RuntimeException: Exception in Application start method
>!  at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:901)
>!  at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
>!  at java.base/java.lang.Thread.run(Thread.java:1623)
>! Caused by: java.lang.IllegalArgumentException: Invalid URL: Invalid URL or resource not found
>!  at javafx.graphics/javafx.scene.image.Image.validateUrl(Image.java:1135)
>!  at javafx.graphics/javafx.scene.image.Image.<init>(Image.java:625)
>!  at com.example.cupoftea/com.example.cupoftea.HelloApplication.start(HelloApplication.java:153)
>!  at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
>!  at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
>!  at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
>!  at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
>!  at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
>!  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:184)
>! 1 more
>! Caused by: java.lang.IllegalArgumentException: Invalid URL or resource not found
>!  at javafx.graphics/javafx.scene.image.Image.validateUrl(Image.java:1120)
>! 11 more
>! Exception running application com.example.cupoftea.HelloApplication

for whatever reason when I was trying to add photos and images it would not work without me having the full path, I don't like it, but I can't seem to fix it.

I have tried to use this:

"C:/Users/myUser/IdeaProjects/CupOfTea/src/main/resources//main.css"

code I have seen but it throws this error: Exception in Application start method

>! java.lang.reflect.InvocationTargetException
>!  at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
>!  at java.base/java.lang.reflect.Method.invoke(Method.java:578)
>!  at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:465)
>!  at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:364)
>!  at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
>!  at java.base/java.lang.reflect.Method.invoke(Method.java:578)
>!  at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1081)
>! Caused by: java.lang.RuntimeException: Exception in Application start method
>!  at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:901)
>!  at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
>!  at java.base/java.lang.Thread.run(Thread.java:1623)
>! Caused by: java.lang.NullPointerException: Cannot invoke "java.net.URL.toExternalForm()" because the return value of "java.lang.Class.getResource(String)" is null
>!  at com.example.cupoftea/com.example.cupoftea.HelloApplication.start(HelloApplication.java:152)
>!  at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
>!  at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
>!  at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
>!  at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
>!  at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
>!  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:184)
>! 1 more
>! Exception running application com.example.cupoftea.HelloApplication
Any help is greatly appreciated; 

0 Answers0