I got the following error today: java.lang.NoSuchMethodError: javax.swing.JList.getSelectedValuesList()Ljava/util/List;
We have some customers still using old java6 versions out there. (Some old posready/embedded-version of windows that doesn't accept installing 1.8 directly..) Therefore I use compiler compliance level 1.6 in eclipse. However, after an upgrade of our software, some customers reported errors/freezing. I logged in, and found the following error: java.lang.NoSuchMethodError: getSelectedValuesList()Ljava/util/List; It appears that this particular JList method in was introduced in 1.7, and I have started using it since getSelectedValues() is deprecated. But this breaks things on 1.6, since the method does not exist in 1.6. I have made a workaround, instead of calling getSelectedValuesList() I now call the following method:
public static <E> java.util.List<E> getSelectedValuesList(javax.swing.JList<E> l) {
try {
return l.getSelectedValuesList();
}catch(java.lang.NoSuchMethodError err) {
ArrayList<E> v = new ArrayList<E>();
Object[] oo = l.getSelectedValues();
for (Object o : oo) {
v.add((E)o);
}
return v;
}
}
This seems to work ok. But my question is, since source level is 1.6, how do I detect similar errors? Since I don't even have 1.6 installed, how can I know for sure that all my swing methods that I call actually works in 1.6? I don't want to introduce yet another bug later on. :-)