不可序列化的组布局无法弄明白

时间:2015-10-19 10:51:18

标签: java

此后还有更多,但这显然是最相关的,如果需要我可以添加更多的错误甚至更具体的代码,但我已经明白了我已经放弃了解决这个问题。我无法弄清楚如何。我之前尝试过它可以工作的另一个框架,但是这个框架没有。

java.io.NotSerializableException: javax.swing.GroupLayout
     atjava.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)




    package GuiM;

    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.ObjectOutputStream;
    import java.io.Serializable;
    import java.util.List;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.JOptionPane;

public class Addpanel extends javax.swing.JPanel {

    List<Item> items;
    private String name;
    private String city;
    private String gender;
    private float bal;
    private int age;
    private int pin;
    private int acn;
    private boolean exeption = true;
    private boolean exist = false;
    public Addpanel(List<Item> items) {
        this.items = items;
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        acnt = new javax.swing.JTextField();
        pint = new javax.swing.JTextField();
        namet = new javax.swing.JTextField();
        cityt = new javax.swing.JTextField();
        aget = new javax.swing.JTextField();
        gendert = new javax.swing.JTextField();
        balt = new javax.swing.JTextField();
        addbtn = new javax.swing.JButton();

        setBackground(new java.awt.Color(204, 204, 255));

        jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
        jLabel1.setText("ACC. NUMBER");

        jLabel2.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
        jLabel2.setText("NAME");

        jLabel3.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
        jLabel3.setText("PIN NUMBER");

        jLabel4.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
        jLabel4.setText("CITY");

        jLabel5.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
        jLabel5.setText("GENDER");

        jLabel6.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
        jLabel6.setText("AGE");

        jLabel7.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
        jLabel7.setText("BALANCE");

        acnt.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
        acnt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                acntActionPerformed(evt);
            }
        });

        pint.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N

        namet.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N

        cityt.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N

        aget.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N

        gendert.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N

        balt.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N

        addbtn.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
        addbtn.setText("ADD");
        addbtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addbtnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3)
                            .addComponent(jLabel2)
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(addbtn)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(namet)
                                .addComponent(acnt)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(gendert, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(18, 18, 18)
                                    .addComponent(jLabel6)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(aget, javax.swing.GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE))
                                .addComponent(cityt, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(pint, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(balt)))
                        .addGap(0, 17, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(acnt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(namet, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(pint, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(cityt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(4, 4, 4)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6)
                    .addComponent(aget, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(gendert, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addComponent(balt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(addbtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>                        

    private void acntActionPerformed(java.awt.event.ActionEvent evt) {                                     
        // TODO add your handling code here:
    }                                    

    private void addbtnActionPerformed(java.awt.event.ActionEvent evt) {                                       
        // TODO add your handling code here:
        name = namet.getText();
        gender = gendert.getText();
        city = cityt.getText();
        try{
        acn = Integer.parseInt(acnt.getText());
        pin = Integer.parseInt(pint.getText());
        age = Integer.parseInt(aget.getText());
        bal = Float.parseFloat(balt.getText());}
        catch(NumberFormatException ex){
            JOptionPane.showMessageDialog(this, "ACCNOUT NUMBER\nAGE\nPIN\nBALANCE\nMUST BE A NUMBER!");
            exeption = false;
        }
        if (exeption == true) {
            for (Item i : items) {
                if (i.getPin()== pin || i.getAcn() == acn) {
                    JOptionPane.showMessageDialog(this, "PIN OR ACCOUNT NUMBER\nIS ALREADY USED");
                    exist = true;
                }
            }
        }
        if(exist == false && exeption == true){
        items.add(new Item(name, city, gender, bal, age, pin, acn));
        JOptionPane.showMessageDialog(gendert, "SUCCESS!");
        }
        exeption = true;
        exist = false;
        namet.setText(null);
        gendert.setText(null);
        aget.setText(null);
        cityt.setText(null);
        balt.setText(null);
        pint.setText(null);
        acnt.setText(null);

        try {
            FileOutputStream fos = new FileOutputStream("c:\\xxx.dat");
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(items);
            oos.close();
            fos.close();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Addpanel.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Addpanel.class.getName()).log(Level.SEVERE, null, ex);
        }

    }                                      


    // Variables declaration - do not modify                     
    private javax.swing.JTextField acnt;
    private javax.swing.JButton addbtn;
    private javax.swing.JTextField aget;
    private javax.swing.JTextField balt;
    private javax.swing.JTextField cityt;
    private javax.swing.JTextField gendert;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JTextField namet;
    private javax.swing.JTextField pint;
    // End of variables declaration                   
}

    /*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package GuiM;

import java.awt.BorderLayout;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;

/**
 *
 * @author Administrator
 */
public class MainFrame extends javax.swing.JFrame {

    List<Item> items;
    String password = "1234";
    String inputpass;
    int pin;
    boolean pinx = false;
    public MainFrame() {
        items = read();
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jButton6 = new javax.swing.JButton();
        panel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        addbtn = new javax.swing.JButton();
        wbtn = new javax.swing.JButton();
        dbtn = new javax.swing.JButton();
        tbtn = new javax.swing.JButton();
        delbtn = new javax.swing.JButton();

        jButton6.setText("jButton1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(255, 255, 255));
        setPreferredSize(new java.awt.Dimension(600, 400));
        setResizable(false);
        setSize(new java.awt.Dimension(600, 400));

        panel.setBackground(new java.awt.Color(204, 204, 255));

        jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N
        jLabel1.setText("WELCOME");

        jLabel2.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N
        jLabel2.setText("AUTOMATED");

        jLabel3.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N

        jLabel4.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N
        jLabel4.setText("MACHINE");

        jLabel5.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N
        jLabel5.setText("TELLER");

        javax.swing.GroupLayout panelLayout = new javax.swing.GroupLayout(panel);
        panel.setLayout(panelLayout);
        panelLayout.setHorizontalGroup(
            panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(225, 225, 225))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelLayout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(216, 216, 216))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelLayout.createSequentialGroup()
                        .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel4)
                            .addGroup(panelLayout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addGap(12, 12, 12)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel3)
                        .addGap(226, 226, 226))))
        );
        panelLayout.setVerticalGroup(
            panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelLayout.createSequentialGroup()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(4, 4, 4)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelLayout.createSequentialGroup()
                        .addGap(65, 65, 65)
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panelLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(104, Short.MAX_VALUE))
        );

        addbtn.setFont(new java.awt.Font("Times New Roman", 1, 11)); // NOI18N
        addbtn.setText("ADD ACC.");
        addbtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addbtnActionPerformed(evt);
            }
        });

        wbtn.setFont(new java.awt.Font("Times New Roman", 1, 11)); // NOI18N
        wbtn.setText("WITHDRAW");
        wbtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                wbtnActionPerformed(evt);
            }
        });

        dbtn.setFont(new java.awt.Font("Times New Roman", 1, 11)); // NOI18N
        dbtn.setText("DEPOSIT");
        dbtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dbtnActionPerformed(evt);
            }
        });

        tbtn.setFont(new java.awt.Font("Times New Roman", 1, 11)); // NOI18N
        tbtn.setText("TRANSFER");
        tbtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tbtnActionPerformed(evt);
            }
        });

        delbtn.setFont(new java.awt.Font("Times New Roman", 1, 11)); // NOI18N
        delbtn.setText("DELETE ACC.");
        delbtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                delbtnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(panel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(addbtn)
                        .addGap(18, 18, 18)
                        .addComponent(delbtn)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
                        .addComponent(dbtn, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(tbtn, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(wbtn)
                        .addGap(21, 21, 21))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(panel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 40, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(wbtn, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tbtn, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(dbtn, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(delbtn, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(addbtn, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(27, 27, 27))
        );

        pack();
    }// </editor-fold>                        

    private void addbtnActionPerformed(java.awt.event.ActionEvent evt) {                                       
        // TODO add your handling code here:
        inputpass = JOptionPane.showInputDialog("ENTER PASSWORD");
        if (!inputpass.equals(password)){JOptionPane.showMessageDialog(this, "THE PASSWORD IS WRONG");}
        else{
            panel.removeAll();
            panel.setVisible(false);
            panel.setLayout(new BorderLayout());
            panel.add(new Addpanel(items), BorderLayout.CENTER);
            panel.repaint();;
            panel.setVisible(true);
        }
    }                                      

    private void wbtnActionPerformed(java.awt.event.ActionEvent evt) {                                     
        // TODO add your handling code here:
        panel.removeAll();
        panel.setVisible(false);
        panel.setLayout(new BorderLayout());
        panel.add(new Withdraw(items), BorderLayout.CENTER);
        panel.repaint();
        panel.setVisible(true);
    }                                    

    private void dbtnActionPerformed(java.awt.event.ActionEvent evt) {                                     
        // TODO add your handling code here:
        panel.removeAll();
        panel.setVisible(false);
        panel.setLayout(new BorderLayout());
        panel.add(new Deposit(items), BorderLayout.CENTER);
        panel.repaint();
        panel.setVisible(true);
    }                                    

    private void delbtnActionPerformed(java.awt.event.ActionEvent evt) {                                       
        // TODO add your handling code here:
       inputpass = JOptionPane.showInputDialog("ENTER PASSWORD");
        if (!inputpass.equals(password)){JOptionPane.showMessageDialog(this, "THE PASSWORD IS WRONG");}
        else{
            panel.removeAll();
            panel.setVisible(false);
            panel.setLayout(new BorderLayout());
            panel.add(new EditDeletepanel(items), BorderLayout.CENTER);
            panel.repaint();;
            panel.setVisible(true);
        }
    }                                      

    private void tbtnActionPerformed(java.awt.event.ActionEvent evt) {                                     
        // TODO add your handling code here:
        panel.removeAll();
        panel.setVisible(false);
        panel.setLayout(new BorderLayout());
        panel.add(new Transfer(items), BorderLayout.CENTER);
        panel.repaint();
        panel.setVisible(true);
    }                                    

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainFrame().setVisible(true);
            }
        });
    }
    public List<Item> read(){
        ArrayList<Item> items = null;
        try {
            FileInputStream fis = new FileInputStream("c:\\xxx.txt");
            ObjectInputStream ois = new ObjectInputStream(fis);
            items = (ArrayList<Item>)ois.readObject();
            ois.close();
            fis.close();
        } catch (Exception ex) {}
        return (items == null)? new ArrayList<Item>() {}: items;
    }

    // Variables declaration - do not modify                     

}

1 个答案:

答案 0 :(得分:0)

一般来说,Swing和AWT对象不是Serializable。除了不尝试保存包含对这些对象之一的引用的任何内容之外,您无法做到这一点。一种方法是更改​​包含对transient的引用的字段。

在这种情况下,您显然正在尝试序列化Item个对象的列表。这不是标准的Java SE类,所以我猜测它是一个直接或间接包含对javax.swing.GroupLayout对象的引用的自定义类。

更新 - 显然不是。这导致我怀疑异常来自您未向我们展示的代码的另一部分。异常消息明确指出writeObject正在尝试序列化包含对javax.swing.GroupLayout对象的引用的内容。

(或许Item是在具有javax.swing.GroupLayout字段的类中声明的内部类?)