i have seen other answers but nothing have helped me
(sorry new to GUI only know basics of swing)
this is main class
package application;
imp
try{
scene.getStylesheets().add(new File(pathTocssFile).toURI().toURL().toExternalForm());
} catch (MalformedURLException e) {
e.printStackTrace();}
getClass().getClassLoader().getResource(...)
will load a resource from a path relative to the classpath. Since you placed the FXML file in the application
pacakge, you need:
Parent root=FXMLLoader.load(getClass().getClassLoader().getResource("application/Main.fxml"));
If you just use getClass().getResource(...)
, and do not prefix the path with /
, it will load from a path relative to the current class. So
Parent root=FXMLLoader.load(getClass().getResource("Main.fxml"));
should also work.
Make sure that your FXML file is being exported to the build folder, along with the .class
files.