I am just starting out with JavaFX, and I am trying to build a simple application with a label, text field and button which, when clicked, sets the label\'s value to that of
Another cause might be missing VM options:
--module-path <path-to-javafx>/javafx-sdk-11.0.2/lib
--add-modules=javafx.controls,javafx.fxml
For anyone who has this exact same problem in the future, as James_D and the other answer contributors mentioned, removing the "/" at the beginning of the path fixes the problem so use
FXMLLoader loader = new FXMLLoader(Main.class.getResource("MainWindowView.fxml"));
instead of
FXMLLoader loader = new FXMLLoader(Main.class.getResource("/MainWindowView.fxml"));
I've been looking through this thread and the answers but the cases are a bit different for me
the code written in the main file is not as mentioned like this:
FXMLLoader loader = new FXMLLoader(Main.class.getResource("MainWindowView.fxml"));
the code in my case is like this:
FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml"));
and I encountered the same error(approx.)
guess its this ?
@FXML
void handleButton(ActionEvent event) {
The same problem happened to me. It's because of maven library. I have different version of jfoenix library in scene builder jfoenix:0.1.8 and in IDE jfoenix:9.0.9.so i downloaded the same version in both and it worked for me.
And also for the nullpointer exception this code worked for me:
FXMLLoader fxmlLoader=new FXMLLoader (Main.class.getResource ("sample.fxml"));
Parent root =fxmlLoader.load ();
The fxml
file and Main
is in same package.
Perform the following operation
FXMLLoader loader = new FXMLLoader(Main.class.getResource("MainWindowView.fxml"));
Parent root = loader.load();
Remove / from in front of .fxml file name. I think it should work. It solved the same error for me.