The exception isn't thrown at listmodel.clear(), it's thrown downstream at line 26, i.e. list.getSelectedValue().toString() in the list listener - the exception message tells you that:

...