当前位置:编程学习 > JAVA >>

求指点,大神们

这个异常是什么意思啊,怎么解决啊?
java.io.NotSerializableException: javax.swing.plaf.metal.MetalFileChooserUI
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1180)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
at javax.swing.event.EventListenerList.writeObject(EventListenerList.java:257)
at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:962)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1480)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528)
at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:438)
at javax.swing.JComponent.writeObject(JComponent.java:5525)
at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:962)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1480)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528)
at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:438)
at java.awt.Window.writeObject(Window.java:2893)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:962)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1480)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
at java.awt.Window.writeObject(Window.java:2910)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:962)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1480)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
at LoanJFrame.writetofile(LoanJFrame.java:155)
at LoanJFrame.actionPerformed(LoanJFrame.java:206)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6504)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6269)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4860)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4686)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2713)
at java.awt.Component.dispatchEvent(Component.java:4686)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:680)
at java.awt.EventQueue$4.run(EventQueue.java:678)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90) --------------------编程问答-------------------- 把代码也贴出来吧 --------------------编程问答-------------------- import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;

import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.DefaultTableModel;
public class LoanJFrame extends JFrame implements ActionListener
{
private File file;
private JFileChooser fchooser;
    private JTextField text_money, text_rate, text_year;   //贷款金额、利率、年限文本行
    private JSpinner spin_year, spin_month;                //起始年月微调文本行
    private JButton button;                                //计算按钮
    private JTable table;                                  //表格
    Object datas[][]=new Object[0][5];                //创建存储表格数据项的二维数组
    String titles[]={"年月","本金余额(元)","月还本金(元)","月还利息(元)","月还本息(元)"};
    String[]header=titles;//定义表头
    String ss[]=new String[5];//每一行的数据
    JScrollPane js;
    DefaultTableModel model;//用表头生成一个DefaultTableModel 对象
    public LoanJFrame()
    {
        super("银行贷款按月还本付息的计算");
        this.setBounds(200,200,1000,500);
        this.setResizable(false);
        this.setBackground(java.awt.Color.lightGray);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        JPanel panel = new JPanel();
        this.getContentPane().add(panel, "North");
        panel.add(new JLabel("贷款金额"));
        text_money = new JTextField("100000",6);
        panel.add(text_money);
 
        panel.add(new JLabel("元    贷款利率"));
        text_rate = new JTextField("0.5025",6);
        panel.add(text_rate);
        panel.add(new JLabel("%/月    贷款年限"));
        text_year = new JTextField("5",3);
        panel.add(text_year);

        panel.add(new JLabel("年    起始年月"));
        Calendar today = Calendar.getInstance();           //获得当前日期
        int year=today.get(Calendar.YEAR);                 //当年
        int nextmonth=today.get(Calendar.MONTH)+1;         //get(Calendar.MONTH)范围是0~11
        nextmonth = nextmonth%12+1;                        //下月
        if (nextmonth==1)                                  //12月的下月是次年1月
            year++;
        spin_year = new JSpinner();
        spin_year.setValue(year);                          //设置值
        panel.add(spin_year);
        panel.add(new JLabel("年"));
        spin_month=new JSpinner(new SpinnerNumberModel(nextmonth, 1, 12, 1));
                                                           //数值模式初值为下月,范围是1~12,变化值为1
        panel.add(spin_month);
        panel.add(new JLabel("月"));
        button = new JButton("计算");
        panel.add(button);
        button.addActionListener(this);
        JButton bopen=new JButton("打开");
        bopen.addActionListener(this);
        panel.add(bopen);
        JButton bsave=new JButton("保存");
        bsave.addActionListener(this);
        panel.add(bsave);
        table=new JTable(datas, titles);                   //创建表格,datas指定数据,titles指定列标题
        js=new JScrollPane(table);
        this.getContentPane().add(js); //滚动窗格(包含表格)添加到框架内容窗格中部
        this.file=null;
        this.fchooser=new JFileChooser(new File(".",""));
        this.fchooser.setFileFilter(new FileNameExtensionFilter("利息数据文件(*.dat)","dat"));
        this.setVisible(true);
    }

    public void updateTable(Object[] objTable)
  {
  model.addRow(objTable);//给model对象添加数据行
  table.setModel(model);//把model作为JTable的数据来源
  }
    public class LixiData  implements java.io.Serializable
    {
      String data[]=new String[5];
     public LixiData(String str[])
     {
     this.data=str;
     }    
    }
    public class ShowData extends JDialog
    {
     private JTable table;
     DefaultTableModel model;//用表头生成一个DefaultTableModel 对象
        Object datas[][]=new Object[0][5];                //创建存储表格数据项的二维数组
        String titles[]={"年月","本金余额(元)","月还本金(元)","月还利息(元)","月还本息(元)"};
        String[]header=titles;//定义表头
        String ss[]=new String[5];//每一行的数据
        JScrollPane js;
     public ShowData(JFrame jframe)
     {
     super(jframe,"数据信息",true);
     this.setBounds(500,150,600,400);
     this.setResizable(false);
     this.setDefaultCloseOperation(HIDE_ON_CLOSE);
     this.getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER));
     table=new JTable(datas, titles);   //创建表格,datas指定数据,titles指定列标题
            js=new JScrollPane(table);
            this.getContentPane().add(js);     //滚动窗格(包含表格)添加到框架内容窗格中部
     FileInputStream fin=null;
     ObjectInputStream objin=null;
     boolean f=true;
     try
     {
     fin=new FileInputStream(file);
     objin=new ObjectInputStream(fin);
     }catch(Exception e){JOptionPane.showMessageDialog(this,"文件不合法!");f=false;}
     if(f)
     {
     while(true)
     try
         {
     LixiData lixi=(LixiData)objin.readObject();
     this.updateTable(lixi.data);
             }catch(Exception ex){break;}
             try
             {
             objin.close();
             fin.close();
             }catch(Exception ex){}
     this.setVisible(true);
     }
     }
     public void updateTable(Object[] objTable)
     {
     model.addRow(objTable);//给model对象添加数据行
     table.setModel(model);//把model作为JTable的数据来源
     }
    }
    public void writetofile()
    {
     LixiData lixi[]=new LixiData[table.getRowCount()];
     for(int i=0;i<table.getRowCount();i++)
     {
     String str[]={table.getValueAt(i,0)+"",table.getValueAt(i,1)+"",table.getValueAt(i,2)+"",
     table.getValueAt(i,3)+"",table.getValueAt(i,4)+"",};
     lixi[i]=new LixiData(str);
     }
     FileOutputStream fout=null;
     ObjectOutputStream objout=null;
     Object objs[]=lixi;
     try
     {
     fout=new FileOutputStream(this.file);
     objout=new ObjectOutputStream(fout);
     for(int i=0;i<objs.length;i++)
         objout.writeObject(objs[i]);
     objout.close();
     fout.close();
     }catch(Exception e){e.printStackTrace();}
    }
    public void actionPerformed(ActionEvent e)             //单击事件处理方法
    {
     if(e.getActionCommand()=="计算")
     {  model=new DefaultTableModel(header,0);
            int months=Integer.parseInt(text_year.getText())*12;   //还款月数
            int year=Integer.parseInt(""+spin_year.getValue());    //起始年份
            int mon=Integer.parseInt(""+spin_month.getValue());    //起始月份
            double leavings=Double.parseDouble(""+text_money.getText()); //本金余额
            double pay=leavings/months;                            //月还本金
            double rate=Double.parseDouble(""+text_rate.getText());//贷款利率
            if(months>0)
             for (int i=0; i<months; i++)
             {
             ss[0] = year+"年"+mon+"月";
                    ss[1] = String.format("%9.2f",leavings);
                    ss[2] = String.format("%9.2f",pay);               //月还本金
                    ss[3] = String.format("%9.2f",leavings*rate);     //月还利息
                    ss[4] = String.format("%9.2f",pay+leavings*rate); //月还本息
                    this.updateTable(ss);
                    if (mon==12)
                     year++;
                    mon = mon%12+1;                                //下月
                    leavings -= pay;                               //本金余额减去月还本金
             }
            else
            {
             String voids[]=new String[5];          //如果年限为0清空表格
    this.updateTable(voids);
    model.removeRow(0);
            }
     }
     if(e.getActionCommand()=="打开"&&fchooser.showOpenDialog(this)==JFileChooser.APPROVE_OPTION)
     {
     this.file=fchooser.getSelectedFile();
     this.setTitle(this.file.getName());
     new ShowData(this);
     }
     else if(e.getActionCommand()=="保存"&&this.file!=null)
     {
     this.writetofile();
     }
     else if(e.getActionCommand()=="保存"&&this.file==null&&fchooser.showSaveDialog(this)==JFileChooser.APPROVE_OPTION)
     {
     this.file=fchooser.getSelectedFile();
     if(!file.getName().endsWith(".dat"))
     this.file=new File(file.getAbsolutePath()+".dat");
     this.writetofile();
     this.setTitle(this.file.getName());
     }
    }
    
    public static void main(String args[])
    {
        new LoanJFrame();
    }
}

--------------------编程问答-------------------- --------------------编程问答-------------------- 你的代码是自己写的还是从哪COPY的。 --------------------编程问答--------------------
引用 4 楼 walkman_22 的回复:
你的代码是自己写的还是从哪COPY的。

给程序添加对文件操作的功能是我帮同学写的.... --------------------编程问答-------------------- 这个类没有序列化,让它实现一个Serializable接口。
补充:Java ,  Java SE
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,