I\'m trying to load a CSS file into JavaFX using this line of code and it gives me a null pointer exception:
scene.getStylesheets().add(welcome.class.getReso
Any resource should be on the classpath to be loaded successfully (if it is in the same folder as you welcome class then it is already so). Then you should precede the path to the stylesheet file by '/' symbol, so that it looks like this:
scene.getStylesheets().add(welcome.class.getResource("/background.css").toExternalForm());
Then it will load successfully.