我想从我的 JTable
序列化模型,不幸的是我得到了 NotSerializedException
。
我的所有字段都是可序列化的,我不明白问题出在哪里。
public class Sauvegarde extends AbstractAction implements Serializable {
private static final long serialVersionUID = 1L;
public DefaultTableModel model;
public Sauvegarde(String string) {
super(string);
}
@Override
public void actionPerformed(ActionEvent e) {
sauve_actionPerformed(e);
System.exit(0);
}
public void sauve_actionPerformed(ActionEvent e) {
this.model = Grille.dfm;
try {
// Serialisation
FileOutputStream fos = new FileOutputStream("sauve.tmp");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(model);
oos.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
这是我创建 JTable 和模型的类:
String[] columnTitles = { "A", "B", "C", "D", "E"};
String[] cellulesVide = { "", "", "", "", ""};
String[][] rowData = new String[nombreDeLignes][5];
dfm = new DefaultTableModel(columnTitles,0);
//table.setCellSelectionEnabled(true);
for (int i = 0 ; i < nombreDeLignes ; i++)
{
dfm.addRow(cellulesVide);
}
table = new JTable(dfm) {
最佳答案
没有魔法。
您应该检查对象层次结构中的所有类及其字段。 所有字段和类都应该是可序列化的或原始的。
父级可能不可序列化,但它必须有一个默认构造函数。
如果上述条件成立,它应该有效。
关于java.io.NotSerializedException : java. lang.reflect.Constructor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14426539/