I'm working with JavaFX and trying to incorporate a CSS file into my scene.
scene.getStyleSheets().add(Main.class.getResource("res/application.css").toExternalForm();
An NPE is being thrown. I suspect it's because the css file isn't located within the classpath. But I'm unsure how to tackle loading it in this manner. I prefer not to have the css file in my package directory (com.somecompany.package). Instead, I'd like it to be in a separate directory for independent deployment (allowing users to modify if needed).
Is there a way to load a css file (or any resource) from outside the classpath?
Here is my stack trace:
java.lang.NullPointerException
at com.somecompany.someapp.Main.start(Main.java:30)
at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:206)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:173)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
at java.lang.Thread.run(Unknown Source)