我正在尝试使用 ObjectOutputStream 和 FileOutputStream 序列化对象,但是显示类名错误。
JFileChooser fc = new JFileChooser();
NewClientClass AddClient = new NewClientClass(IDNumber.getText(), FirstName.getText(), LastName.getText(), Address.getText(), DateOfBirth.getText(), Profession.getText());
try {
int returnVal = fc.showSaveDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(fc.getSelectedFile().getAbsoluteFile()));
out.writeObject(AddClient); //the application crashes.
out.close();
JOptionPane.showMessageDialog(null, "Successfully Saved");
}
如您所见,我正在声明一个新客户端并从文本框中获取数据。当我检查 tru 调试时,数据已正确存储,唯一的问题是将对象写入文件时。
请问有什么帮助吗?
谢谢