Java, how to retrieve whatever number (int/float/etc) from a spinner

I don’t know why if I try to cast a spinner I get an error always and only at the second consecutive time:

setValue((int)spinner1.getValue(), ID1);
setValue((int)spinner1.getValue(), ID2);

First line no error, second line exception…

I solved by casting as following:

SpinnerNumberModel snm1 = (SpinnerNumberModel)spinner1.getModel();
SpinnerNumberModel snm2 =(SpinnerNumberModel)spinner2.getModel();
setValue(snm1.getNumber().floatValue());
setValue(snm2.getNumber().floatValue())

Substitute floatValue() with what you need 🙂