可能文件位置不对,导致FInput没有正确生成

解决方案 »

  1.   

    位置不对?我在抛出时价了打印信息,好像是EOFException错误,但不知是哪里出错了
      

  2.   

    信息太少,很难看出错误在哪,你贴的代码没什么问题.
    只知道NullPointerException
      

  3.   

    主要代码如下:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import javax.swing.*;
    import java.io.*;
    import java.util.*;
    import myprojects.studentsystem.*;public class AddStudent extends Student implements ActionListener,ItemListener
    {
    Hashtable MyHash=null;
    FileInputStream FInput=null;
    ObjectInputStream OInput=null;
    FileOutputStream FOutput=null;
    ObjectOutputStream OOutput=null;
    File file=null;


    AddStudent(File file)
    {
    this.file=file;
    //Ϊ×éºÏ¿òºÍ°´Å¥Ôö¼Ó¼àÌýÆ÷
    cboOther.addItemListener(this);
    btnOther.addActionListener(this);
    //Ìí¼Ó¼àÌýÆ÷
    btnPrevious.addActionListener(this);
    btnNext.addActionListener(this);
    btnOK.addActionListener(this);
    btnCancel.addActionListener(this);
    btnAdd.addActionListener(this);
    btnDel.addActionListener(this);
    btnModify.addActionListener(this);
    btnSelect.addActionListener(this);
    }
    public void actionPerformed(ActionEvent e)
    {

    if (e.getActionCommand()=="ÉÏÒ»Ìõ")
    {

    }
    else if (e.getActionCommand()=="ÏÂÒ»Ìõ")
    {

    }
    else if(e.getActionCommand()=="È·¶¨")
    {
    //this.disCancel();
    this.setInfo(); //ËùÓÐÊäÈëÈ«²¿¼Í¼ΪѧÉúÐÅÏ¢ÄÚÈÝ
    String stuID="";
    stuID=this.getID(); //»ñµÃѧºÅ
    this.Myprint(); //ºǫ́²âÊÔ£¬ÊÇ·ñÊäÈë³É¹¦£¬DOSÆÁÄ»´òÓ¡ÊäÈëÐÅÏ¢
    System.out.println ("ÊäÈëѧºÅ³¤¶È£º"+stuID.length());
    if (stuID.length()>0)
    {
    try
    {
    FInput=new FileInputStream(file);
    System.out.println (file.getPath());//ºǫ́²âÊÔ´úÂë
    if (OInput==null) System.out.println ("Ô¤ÏȶÔÏóÊäÈëÁ÷¿Õ");
    OInput=new ObjectInputStream(FInput);
    if (OInput!=null) System.out.println ("¶ÔÏóÊäÈëÁ÷fei ¿Õ");
    System.out.println ("OInput=new ObjectInputStream(FInput);");
    MyHash=(Hashtable)OInput.readObject();
    System.out.println ("ÕýÔÚ¶ÁÈëhashtabelÖÐ");
    FInput.close();
    OInput.close();
    System.out.println ("fileclose");
    }
    catch(EOFException eof)
    {
    System.out.println ("EOFException") ;
    }
    catch(Exception eee)
    {
    //eee.printStackTrace();
    System.out.println ("error");
    }

    if(MyHash.containsKey(stuID))
    {
    System.out.println ("ѧºÅÒÑ´æÔÚ");
    String Msg="¸ÃÉú»ù±¾ÐÅÏ¢ÒÑ´æÔÚ,Çëµ½ÐÞ¸ÄÒ³ÃæÐÞ¸Ä";
    JOptionPane.showMessageDialog(this,Msg,"¾¯¸æ",JOptionPane.WARNING_MESSAGE);
    }
    else
    {
    String m="ÊÇ·ñÕæµÄ¼Èë?";
    int ok=JOptionPane.showConfirmDialog(this,m,"È·ÈÏ",JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE);
    if(ok==JOptionPane.YES_OPTION)
    {
    //this.setInfo();
    try
    {
    FOutput=new FileOutputStream(file);
    OOutput=new ObjectOutputStream(FOutput);
    MyHash.put(stuID,this);
    OOutput.writeObject(MyHash);
    FOutput.close();
    OOutput.close();
    this.setEmpty();
    }
    catch(Exception ee)
    {
    System.out.println(ee);
    }
    }
    else
    {
    String Msg="±ØÐëÊäÈëѧºÅ";
    JOptionPane.showMessageDialog(this,Msg,"¾¯¸æ",JOptionPane.WARNING_MESSAGE);
    }
    }
    }
    }
    else if (e.getActionCommand()=="È¡Ïû")
    {

    }
    else if (e.getActionCommand()=="Ôö¼Ó")
    {
    this.disOK();
    }
    else if (e.getActionCommand()=="ɾ³ý")
    {
    this.disOK();
    }
    else if (e.getActionCommand()=="ÐÞ¸Ä")
    {
    this.disOK();
    this.getID();
    this.txtBirth.setText(this.getName());
    }
    else if (e.getActionCommand()=="²éѯ")
    {
    //this.disCancel();

    }
    else if(e.getActionCommand()=="Í˳ö")
    {
    System.exit(0) ;
    System.out.println ("fdsf");
    }

    }
    public void itemStateChanged(ItemEvent i)
    {

    }
    }
      

  4.   

    你在FInput=new FileInputStream(file);
          OInput=new ObjectInputStream(FInput);//出错位置
    之前加一句试试;File f = new File(file);System.out.println(f == null);
      

  5.   

    真烦人,转不成正确的格式贴出来了,通过word转也不行,谁今晚有空,就当收了个徒弟,帮我解一以下问题好吗?我的QQ一直开着,你们谁有QQ?这样通讯的速度比较快。
      

  6.   

    File f = new File(file);System.out.println(f == null);

    为什么?