user525717
user525717

Reputation: 1652

java.util.vector cannot be cast to javax.collections.observablelist

I`m getting this error:

java.util.vector cannot be cast to javax.collections.observablelist

When trying to populate TableView with List

this is my code error occurs on last line

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());
} 

How i can bind List to my table or what is correct way to convert List to ObservableList?

Upvotes: 0

Views: 2222

Answers (1)

Jeffrey
Jeffrey

Reputation: 44808

Use FXCollections to create an ObservableList.

ObservableList<E> observableList = FXCollections.observableList(list);

Upvotes: 1

Related Questions