java - Vector to DefaulTableModel -
i have serilize file cntains datavector of jtable. when wanna deserialize throws error telling me vector cann't cast default tablemodel.
here serialize method:
fileout.writeobject(model2.getdatavector()); //i save data vector.
here deserialization process:
objectinputstream in = new objectinputstream(new fileinputstream("c:/users/harry/desktop/clients.txt")); defaulttablemodel dtm = (defaulttablemodel)in.readobject(); jtable table = new jtable(dtm);
error:
exception in thread "awt-eventqueue-0" java.lang.classcastexception: java.util.vector cannot cast javax.swing.table.defaulttablemodel
how cast vector default table model can deserialize data vector jtable?
broadly speaking have 3 choices:
- serialize entire
defaulttablemodel
. ok short-lived applications should not rely on consistent mechanism storing data long term. - serialize data vector along column count , column names. deserialize data on reader side , construct new
defaulttablemodel
usingdefaulttablemodel(vector, vector)
constructor. note if aware of column names during deserialization won't need pass data on wire. - implement own
tablemodel
, wraps underlyinglist<t>
of serializable data items. preferred choice.
Comments
Post a Comment