younes
younes

Reputation: 11

javafx : java.lang.ClassNotFoundException

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

Answers (2)

thatsIch
thatsIch

Reputation: 848

There are 2 things the FXML must be aware of:

  1. The controller class name with package path

<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">

  1. Imports of all needed classes like in a normal java class file

<?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

hanbin615
hanbin615

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

Related Questions