请问这是什么问题?赶时间,今晚睡不成了,郁闷呀 可能文件位置不对,导致FInput没有正确生成 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 位置不对?我在抛出时价了打印信息,好像是EOFException错误,但不知是哪里出错了 信息太少,很难看出错误在哪,你贴的代码没什么问题.只知道NullPointerException 主要代码如下: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) { }} 你在FInput=new FileInputStream(file); OInput=new ObjectInputStream(FInput);//出错位置之前加一句试试;File f = new File(file);System.out.println(f == null); 真烦人,转不成正确的格式贴出来了,通过word转也不行,谁今晚有空,就当收了个徒弟,帮我解一以下问题好吗?我的QQ一直开着,你们谁有QQ?这样通讯的速度比较快。 File f = new File(file);System.out.println(f == null);?为什么? 线程池ThreadPoolExecutor的先进先出问题 急求一个,servlet头像上传源码。 java如何在一个类中处理另一个类的事件 Hibernate中如何取类中的前100条数据 理行承诺,请hui_feng(盘桃2)来接分。 控制台工程问题! 在线等待!!!! 安装tomcat4的问题 用过freejava工具的高手,请进!!!!!!!!!! 在二维数组中随机产生一个坐标 给这个Server写一个简单的Client Application,应该怎么写呢? 简单问题,怎么把double转成String类型
只知道NullPointerException
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)
{
}
}
OInput=new ObjectInputStream(FInput);//出错位置
之前加一句试试;File f = new File(file);System.out.println(f == null);
?
为什么?