Valentin Vrinceanu
Valentin Vrinceanu

Reputation: 679

JavaFX 2.0 loading fxml files with event handlers fails

i am trying to load a fxml from a subfolder, but it fails. I have the line that make the replace scene content:

private Parent replaceSceneContent(String fxml) throws Exception {
        Parent page = (Parent) FXMLLoader.load(App.class.getResource("skinFolder/fxml/"+fxml), null, new JavaFXBuilderFactory());
        Scene scene = stage.getScene();
        if (scene == null) {
            scene = new Scene(page, 700, 450);
            scene.getStylesheets().add(App.class.getResource("skinFolder/css/defaultSkin.css").toExternalForm());
            stage.setScene(scene);
        } else {
            stage.getScene().setRoot(page);
        }
        stage.sizeToScene();
        return page;
    }

I use this function in the next method:

private void gotoLogin() {
        try {
            replaceSceneContent("login.fxml");
        } catch (Exception ex) {
            Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

The problem is that i got the next errors:

javafx.fxml.LoadException: Method processLogin() does not have the correct signature for an event handler.
    at javafx.fxml.FXMLLoader$Element.processEventHandlerAttributes(Unknown Source)
    at javafx.fxml.FXMLLoader$ValueElement.processEndElement(Unknown Source)
    at javafx.fxml.FXMLLoader.processEndElement(Unknown Source)
    at javafx.fxml.FXMLLoader.load(Unknown Source)
    at javafx.fxml.FXMLLoader.load(Unknown Source)
    at Main.App.replaceSceneContent(App.java:115)
    at Main.App.gotoLogin(App.java:108)
    at Main.App.start(App.java:72)
    at com.sun.javafx.application.LauncherImpl$5.run(Unknown Source)
    at com.sun.javafx.application.PlatformImpl$4.run(Unknown Source)
    at com.sun.javafx.application.PlatformImpl$3.run(Unknown Source)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.access$100(Unknown Source)
    at com.sun.glass.ui.win.WinApplication$2$1.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:722)

Anyone has any ideea what i need to fix so i can make this replace scene content to work?

Thanks

Upvotes: 3

Views: 8469

Answers (1)

Uluk Biy
Uluk Biy

Reputation: 49185

If you are defining an action of Button in FXML file like this:

 <Button text="Login" onAction="#processLogin"/>

then you must define a method in the controller class like as following. Note the signature of processLogin:

    @FXML
    private void processLogin(javafx.event.ActionEvent event) {
        // Process Login
    }

Upvotes: 7

Related Questions