Kyllopardiun Kyllopardiun - 6 months ago 127
Java Question

FXML scene builder invalid attribute after filling ComboBox

I have this FXML file, where I tried to populate the ComboBox:

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="650.0" minWidth="750.0" prefHeight="700.0" prefWidth="822.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="table.Table">
<children>
<MenuButton fx:id="dateFilter" layoutX="6.0" layoutY="55.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="114.0" text="Date" />
<ComboBox fx:id="descriptionFilter" editable="true" layoutX="226.0" layoutY="55.0" prefHeight="25.0" prefWidth="204.0" promptText="Series Description">
<items>
<FXCollections fx:factory="observableArrayList">
<String fx:value="1" />
<String fx:value="20" />
<String fx:value="300" />
</FXCollections>
</items>
</ComboBox>
</children>
</AnchorPane>


But since I populated it, it won't open on SceneBuilder and it displays this error:

Error


java.io.IOException: javafx.fxml.LoadException: Invalid attribute.
/C:/Users/BTAP/workspace/Tst/src/table/table.fxml:12



And it won't load my Application:


Caused by: javafx.fxml.LoadException: FXCollections is not a valid type.



Note



if I remove the
fx:factory="observableArrayList"
it loads on the scene builder and show a warning but still won't run my program.

And I don't quite understand since it's the same way as I saw in many examples example1, example2, example3.

Why am I getting this error? Shouldn't it work?

I know how to fill the elements by code, but I am looking for a FXML solution.

Answer

You need an import for the FXCollections class:

<?import javafx.collections.FXCollections ?>