In the program contains a lot of custom classes for table manipulation. The two key classes here are TableIndex, and TableSorter. Their inheritance hierarchy is as follows:
TableSorter extends TableMap
TableMap extends AbstractTableModel
AbstractTableModel implements TableModel
TableIndex implements TableModel.
At some point, a JTable is created that has a TableIndex as it's model:
Later on, this call is made, and it throws a ClassCastException:
table.getModel() returns a TableIndex, which is being (illegally, apparently) cast to a TableSorter. Looking up the inheritance chain, both TableIndex and TableSorter are derived from TableModel. Why, then, is this not working? Is this problem because both classes are not extended from the same superclass? Can someone tell me where the break is?
Yes I verified it. The exception is just your generic ClassCastException, specifying the line number and the file that the exception is being thrown in. No other information is being given.
Originally posted by Dave Wingate:
Could you post the exception you're getting?
Did you verify that getModel() is actually returning an object of type TableIndex?
Originally posted by fred rosenberger:
Both derive from TableModel, so you could cast either TableSorter or TableIndex to a TableModel.
but you can't cast a TableIndex to a TableSorter.
if i had Chihuahua derives from Dog derives from Mammal, and Cat derives from Mammal, i can't cast a Cat as a Dog.