我创建了MapProperty来从数据库中读取信息,如下所示。
命令运行正常,Map,ArrayList正常但错误MapProperty.I希望成员为ListProperty类型,所以我可以将它绑定到控件
public MapProperty<String, ListProperty<String>> mapTaxonomy() {
MapProperty<String, ListProperty<String>> mapTaxonomy = new SimpleMapProperty<>();
try {
preparedStatement = connection.prepareStatement("");
resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
String taxonomy = resultSet.getString("Taxonomy");
ListProperty<String> memberSelector = mapTaxonomy.get(taxonomy);
if (memberSelector == null) {
memberSelector = new SimpleListProperty<>();
mapTaxonomy.put(taxonomy, memberSelector);
}
memberSelector.add(resultSet.getString("Selector"));
}
} catch (SQLException ex) {
Logger.getLogger(ParserService.class.getName()).log(Level.SEVERE, null, ex);
}
return mapTaxonomy;
}
@Override
public void initialize(URL location, ResourceBundle resources) {
MapProperty<String, ListProperty<String>> mapTaxonomy = mapTaxonomy();
}
运行以下错误声明后,请帮助我
Caused by: java.lang.UnsupportedOperationException
at java.util.AbstractMap.put(AbstractMap.java:209)
at javafx.beans.binding.MapExpression.put(MapExpression.java:262)
at touya.akira.storages.database.table.parser.ParserService.mapTaxonomy(ParserService.java:70)
at touya.akira.parser.styles.fixed.method.pagination.PaginationPresenter.initialize(PaginationPresenter.java:64)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
... 67 more
答案 0 :(得分:1)
SimpleMapProperty
的默认值是空 不可修改的 地图。尝试修改它时会引发异常。指定可修改的ObservableMap
作为初始值以解决此问题。
MapProperty<String, ListProperty<String>> mapTaxonomy = new SimpleMapProperty<>(FXCollections.observableHashMap());