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:

  1. serialize entire defaulttablemodel. ok short-lived applications should not rely on consistent mechanism storing data long term.
  2. serialize data vector along column count , column names. deserialize data on reader side , construct new defaulttablemodel using defaulttablemodel(vector, vector) constructor. note if aware of column names during deserialization won't need pass data on wire.
  3. implement own tablemodel, wraps underlying list<t> of serializable data items. preferred choice.

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -