I have the following FXML fragment:
<TableView id="studentRecords">
<columns>
<TableColumn text="Name" prefWidth="40" />
<TableColumn text="Marks" prefWidth="60" />
<TableColumn text="Notes" prefWidth="40" />
</columns>
<items>
<String fx:value="" />
<String fx:value="" />
<String fx:value="" />
</items>
</TableView>
I get this error at runtime:
java.lang.IllegalArgumentException: Unable to coerce to interface javafx.collections.ObservableList.
at com.sun.javafx.fxml.BeanAdapter.coerce(BeanAdapter.java:725)
at com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:437)
at com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:44)
at javafx.fxml.FXMLLoader$PropertyElement.set(FXMLLoader.java:1148)
at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:614)
...
Most places in the platform where we use ObservableList it is as an immutable reference, and thus FXML knows to do a getFoo().setAll() in order to avoid having to use <FXCollections> element in the FXML. However for ListView, TableView, etc where the ObservableList reference is mutable, it attempts to create a new List and then set it, leading to this error.
I'm not sure what the right answer is here, but having to use <FXCollections> (or even if it were possible, <ObservableArrayList>) is cumbersome. Rather, it seems in this case if I don't specify a new ObservableList, then the <String>'s should be added to the existing one? I'm not sure if that is the right answer or not.
<TableView id="studentRecords">
<columns>
<TableColumn text="Name" prefWidth="40" />
<TableColumn text="Marks" prefWidth="60" />
<TableColumn text="Notes" prefWidth="40" />
</columns>
<items>
<String fx:value="" />
<String fx:value="" />
<String fx:value="" />
</items>
</TableView>
I get this error at runtime:
java.lang.IllegalArgumentException: Unable to coerce to interface javafx.collections.ObservableList.
at com.sun.javafx.fxml.BeanAdapter.coerce(BeanAdapter.java:725)
at com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:437)
at com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:44)
at javafx.fxml.FXMLLoader$PropertyElement.set(FXMLLoader.java:1148)
at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:614)
...
Most places in the platform where we use ObservableList it is as an immutable reference, and thus FXML knows to do a getFoo().setAll() in order to avoid having to use <FXCollections> element in the FXML. However for ListView, TableView, etc where the ObservableList reference is mutable, it attempts to create a new List and then set it, leading to this error.
I'm not sure what the right answer is here, but having to use <FXCollections> (or even if it were possible, <ObservableArrayList>) is cumbersome. Rather, it seems in this case if I don't specify a new ObservableList, then the <String>'s should be added to the existing one? I'm not sure if that is the right answer or not.
- duplicates
-
JDK-8117600 Default List properties behave differently than standard properties
-
- Closed
-