I am well aware that this question has been asked before (several times), but I've reviewed the 'solutions' on what I could find (adding css file to stylesheets in javafx, Loading css using JavaFX null pointer exception in eclipse, CSS stylesheet not loading) and nothing has seemed to work.
Here is the line of code in question:
scene.getStylesheets().add(getClass().getResource("MainMenu.css").toExternalForm()); //this code gives a nullpointerexception
In every other project I have had this code has worked fine, so I don't understand what the problem is. The only difference I can think of is that this is within a git repository.
To answer some questions that I've seen asked:
Yes, I have initialized the scene, the scene is not the problem and the program runs fine without the line of code above.
Yes, I have tried adding a backslash before the name. It did not work
Yes, the css file is in the same folder as the .java file
Yes, I have included the package at the top of the .java file
The file is purely named "MainMenu.css", not "MainMenu.css.txt" or "MainMenu.css.css"
I can't for the life of me understand where the problem is. Is it a typo? Did I miss something? Help would really be appreciated.
If it helps any, I'm using Java 8 with Maven through Visual Studio Code.