2

I'm trying to include controller(SelectedIssueController) in my main layout (main.fxml). But I get the following error:

Can not set lt.mypackage.controllers.SelectedIssueController field lt.mypackage.controllers.MainController.selectedIssueController to javafx.scene.layout.VBox

Line in main.fxml:

  <fx:include fx:id="selectedIssueController" source="controllers/selectedissue.fxml" />

My selectedissue.fxml:

<VBox xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="lt.mypackage.controllers.SelectedIssueController" fillWidth="false" SplitPane.resizableWithParent="false">
    <children>
     .....
     .....
    </children>
</VBox>

Line in MainController:

@FXML
private SelectedIssueController selectedIssueController;

As I understand it injects VBox object now, but I need SelectedIssueController. What is wrong with my current implementation?

1 Answer 1

6

The FXMLLoader appends Controller to the fx:id specified in the fx:include element to get the name of the field to inject the controller to. Therefore it should be either:

@FXML
private SelectedIssueController selectedIssueControllerController;

or

<fx:include fx:id="selectedIssue" source="controllers/selectedissue.fxml" />

The value injected to the field without the Controller suffix is the value created for the fx:include, i.e. the Object created for the root of the included fxml.

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

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.