我收到此错误:
java.util.vector cannot be cast to javax.collections.observablelist
尝试用列表填充 TableView 时
这是我的代码错误发生在最后一行
try {
emf = Persistence.createEntityManagerFactory("shopPu");
em = emf.createEntityManager();
List<Products> proList = em.createQuery("select p from Products p").getResultList();
tableView.setItems((ObservableList<Products>)proList);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
如何将 List 绑定(bind)到我的表,或者将 List 转换为 ObservableList 的正确方法是什么?
最佳答案
使用FXCollections
创建一个ObservableList
。
ObservableList<E> observableList = FXCollections.observableList(list);
关于java.util.vector 无法转换为 javax.collections.observablelist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12253737/