【问题标题】:Serializable Exception in Autocomplete configured JComboBox自动完成配置的 JComboBox 中的可序列化异常
【发布时间】:2015-04-09 04:29:00
【问题描述】:

我有一个JTable,并且该表的一列正在使用JComboBox 作为编辑器。这样它工作得很好。然后我继续使用this jar file here 在我的JComboBox 中启用自动完成功能。同样效果很好。

现在我要保存表格中的数据,如下所示;

        public void actionPerformed(ActionEvent e) {
        File outFile= new File("qoutatio.dat");
        try {
            FileOutputStream fous=new FileOutputStream(outFile);
            ObjectOutputStream obj=new ObjectOutputStream(fous);
            obj.writeObject(table);
            obj.flush();
            obj.close();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
};

程序产生以下错误:

run:
 Feb 09, 2015 2:13:54 PM quotationGenerator.MainWindow$2 actionPerformed
SEVERE: null
java.io.NotSerializableException: org.jdesktop.swingx.autocomplete.AutoCompleteComboBoxEditor
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:441)
at javax.swing.JComboBox.writeObject(JComboBox.java:1569)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

这表明 jar 文件中的一个类不是Serializable.Understood。我的问题:有没有办法制作这个Serializable?我们如何解决这个问题?

【问题讨论】:

    标签: java swing jtable serializable


    【解决方案1】:

    一种选择是创建您自己的扩展org.jdesktop.swingx.autocomplete.AutoCompleteComboBoxEditor 并实现Serializable 的类,并将此类设置为组合框上的编辑器。

    【讨论】:

      猜你喜欢
      • 2012-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-18
      • 2017-01-23
      • 1970-01-01
      • 2012-05-30
      相关资源
      最近更新 更多