1

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());
    }
}
4
  • Have you included jar containing PageTwoController in classpath ?? Commented Sep 17, 2013 at 19:15
  • the pageTwoController class exists on the same package where the main class, i thing there is no need the import it Commented Sep 17, 2013 at 19:19
  • 1
    How do you link to it in your fxml? Absolute/relative path? Commented Sep 17, 2013 at 19:35
  • @younes, you should include in your question your FXML and controller. Commented Sep 18, 2013 at 8:42

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

if you are using NetBeans, you need to write yourself the import statement of the package in the .fxml file

<?import foldername.*?> 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.