1
我已經做了一個JButton與netbean JFrame中,我想序列化一個對象時,我點擊了一個JButton序列化對象在一個JButton
錯誤:java.io.NotSerializableException:javax.swing.GroupLayout
我不序列化任何佈局,但它爲什麼有這個錯誤?
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
getValue1 a =new getValue1();
a.name=jTextField1.getText();
a.ps=jTextField2.getText();
a.type=jComboBox1.getSelectedItem().toString();
try{
FileOutputStream fileOut =new FileOutputStream("C:\\employee.ser");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(a);
out.close();
fileOut.close();
System.out.printf("C:\\employee.ser");
}
catch(IOException i){
i.printStackTrace();
}
}
public class getValue1 implements java.io.Serializable{
public String name;
public String ps;
public String type;
}
您的getValue1可能是內部類,然後附帶類的成員;嘗試使用*靜態*內部類 –
@philippelhardy你在正確的軌道上,但'靜態內在'是一個矛盾的術語。你應該說'靜態嵌套'。 – EJP
Thks @philippelhardy – user3042789