Reputation: 21
I'm working with JavaFX and trying to use FXML, however I've never had any sort of formal training in it, so I'm kind of stumbling about.
I keep running into this here error: Caused by: javafx.fxml.LoadException: Element does not define a default property.
My aim is to try to initialize a Custom Controller class that runs its own FXML file. The code example given by Oracle therefore looks like this:
<fx:root type="javafx.scene.layout.VBox" xmlns:fx="http://javafx.com/fxml">
<TextField fx:id="textField"/>
<Button text="Click Me" onAction="#doSomething"/>
</fx:root>
where the controller and root is set in the Controller method.
I'm trying to adapt this code to my own needs, and I was wondering if someone could explain to me why this error comes up if the fx:root type="javafx.scene.layout.VBox" is ever changed to something like fx:root type="javafx.scene.Parent" if you want me to, I can post some actual code samples.
Upvotes: 2
Views: 5376
Reputation: 5887
The concept of default-property is introduced to short circuit your FXML in reality you'd have to write:
<fx:root type="javafx.scene.layout.VBox" xmlns:fx="http://javafx.com/fxml">
<children>
<TextField fx:id="textField"/>
<Button text="Click Me" onAction="#doSomething"/>
</children>
</fx:root>
if you now change the container type to Parent and you browse the parent class you'll notice that it does not define a children-property which you implicitly assume - children is introduced by Pane.
You should probably read http://docs.oracle.com/javafx/2/api/javafx/fxml/doc-files/introduction_to_fxml.html
Upvotes: 4