Reputation: 11
i'm new to javafx and i want to load an fxml file to Pane
the problem is when i click to the pageTwo button an exception message says that java.lang.ClassNotFoundException: PageTwoController
here is the code
@FXML
private void pageTwoAction(ActionEvent event) {
try {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("pageTwo.fxml"));
Pane displayArea = (Pane) fxmlLoader.load();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
}
Upvotes: 1
Views: 6152
Reputation: 848
There are 2 things the FXML must be aware of:
<AnchorPane fx:id="root" prefHeight="-1.0" prefWidth="-1.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="countrycode.compoany.project.javafx.PageTwoController">
<?import countrycode.company.project.javafx.*?>
You can either edit them manually or use SceneBuilder especially if you are new to JavaFX it helps a lot in the start
Upvotes: 2
Reputation: 595
if you are using NetBeans, you need to write yourself the import statement of the package in the .fxml file
<?import foldername.*?>
Upvotes: 0