我試圖序列與ObjectOutputStream中和FileOutputStream中的對象序列化對象,但與類名的錯誤被顯示。用java
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調試,唯一的問題是將對象寫入文件。
請幫忙嗎?
感謝
是否你的對象實現java.io.Serializable?請發佈錯誤消息。 – Burkhard
你得到了什麼錯誤(堆棧跟蹤)? – MaVRoSCy
@MaVRoSCy在代碼中檢查評論 –