JAVAFX error incompatible types: FXMLLoader cannot be converted to node

909 views Asked by At

I am new to Java and JavaFX. I am trying to develop an CRUD application for employee data. I am adding the FXML file into a tab. The code is as follows.

tabEmployee.setContent((Node) FXMLLoader.load(getClass().getResource("EmployeeOverview.fxml")));

This works fine but when I try to do the same as follows

private URL URLEmployeeOverview = getClass().getResource("EmployeeOverview.fxml");
FXMLLoader loaderEmployeeOverview = new FXMLLoader(URLEmployeeOverview);
tabEmployee.setContent((Node) loaderEmployeeOverview);

I am getting an error:

incompatible types. FXMLLoader cannot be converted to Node

May I get help on why this happens and how to correct it.

1

There are 1 answers

2
Uluk Biy On BEST ANSWER

You should invoke the load method:

tabEmployee.setContent( (Parent) loaderEmployeeOverview.load() );