Invalid FXML scene builder attribute after ComboBox is populated

I have this FXML file where I tried to populate a 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 filled it, it will not open in SceneBuilder and will display this error:

Error

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

And it will not load my application:

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

Note

if I remove fx:factory="observableArrayList" , it will load into the scene builder and show a warning, but will not execute my program.

And I do not quite understand, since it is the same as I saw in many examples, example1 , example2 , example3 .

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

I know how to populate elements with code, but I'm looking for an FXML solution.

+6
source share
1 answer

You need an import for the FXCollections class:

 <?import javafx.collections.FXCollections ?> 
+12
source

Source: https://habr.com/ru/post/971310/


All Articles