posted 19 years ago
I inherited an unfinished (undocumented and uncommented) program from another programmer (now gone), and I'm trying to figure out a ClassCastException that gets thrown at runtime.
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?
There's nothing more dangerous than a resourceful idiot. ---Dilbert