Tomáš Čičman Tomáš Čičman -3 years ago 168
Java Question

JavaFX How to get data of selected row from Tableview

I would like to get data from one selected row

I have this little code

Stlpce aktualne = (Stlpce) tableview_objednavka.getSelectionModel().getSelectedItems();
double aktcena = aktualne.getCena();

But When I run the app I get this error

Caused by: java.lang.ClassCastException: javafx.scene.control.TableView$TableViewArrayListSelectionModel$5 cannot be cast to sample.Stlpce

I use scene builder for create TableView.

Can you help me?

This is solved - the problem was, that I have
instead of

Answer Source

The exception is clear in its meaning:

The method call you make ( returns a reference to an


Object, which Stlpe does not implement/extend and therefore a Stlpe reference cannot point to such an Object.

Is the Stlpe class the Type class of your ObservableList? If so, maybe you need to find the Stlpe Object in your list:

if (returnedList.size() > 0) {
    Stlpe item = returnedList.get(0);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download