Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ObjectInputStream problem

 
Erre ced
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !
I have a problem whit my program iam doing. I have make a call cald Employees, it has insert, getH, setH.
This is my code for make my register to a fil calld anstald.dat.
Employees register = new Employees();
MonthlyEmployee ME = new MonthlyEmployee();
HashMap reg = new HashMap();
register.setH(reg);
try{fis = new FileInputStream("anstald.dat"); }
catch (FileNotFoundException FNFE){
try {fos = new FileOutputStream("anstald.dat"); }
catch (FileNotFoundException FNFE2){}
try {oos = new ObjectOutputStream(fos); }
catch (IOException IOE){}
try {oos.writeObject(register); }
catch (IOException IOE){}
try {oos.close(); }
catch (IOException IOE){}
try {fis = new FileInputStream("anstald.dat"); }
catch (FileNotFoundException FNFE3){}
}
try {ois = new ObjectInputStream(fis); }
catch (IOException IOE){}
try {register = (Employees) ois.readObject();}
catch (IOException IOE){}
catch (ClassNotFoundException CNFE){}
try {ois.close(); }
catch (IOException IOE){}
ME.setName(ntextField.getText());
ME.setId(ptextField.getText());
ME.setAdress(atextField.getText());
ME.setPhone(ttextField.getText());
int m�n=Integer.parseInt(m�ntextField.getText());
ME.setMonthlySalary(m�n);
register.insert(ME);
try {fos = new FileOutputStream("anstald.dat"); }
catch (FileNotFoundException FNFE){}
try {oos = new ObjectOutputStream(fos); }
catch (IOException IOE){}
try
{oos.writeObject(register); }
catch (IOException IOE){}
try {oos.close(); }
catch (IOException IOE){}
this.dispose();
}
than i have make that i whant to search f�r the employee and i have this code for that:
{
Employees register = new Employees();
register.getH();
MonthlyEmployee ME = new MonthlyEmployee();
try {fis = new FileInputStream("anstald.dat"); }
catch (FileNotFoundException FNFE){}
try {ois = new ObjectInputStream(fis);}
catch (IOException IOE){}
try
{register = (Employees) ois.readObject();
ME = (MonthlyEmployee) register.getH().get(sptextField.getText());}
catch (IOException IOE){}
catch (ClassNotFoundException CNFE){}
try {ois.close(); }
catch (IOException IOE){}
try { jLabel1.setText(("Namn: " + ME.getName()+ME.salary())" Kr"); }
catch (NullPointerException NPE)
{jLabel1.setText("Namn: KUND FINNS EJ I REGISTER");}
}
}
Then i drive the program I just get this mess: Null 0Kr
thans for halp
erre
 
Peter van der Linden
author
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Erre,

Put in some println statements so you can see what values
the important variables have at certain stages.

Write them with your expected value too, like this:
System.out.println("int i, expected 17, actually is: " + i);

Then when you find a variable whose value isn't what you expect,
start tracking backwards to find out why.

That's the right way to tackle a simple problem like this.

Cheers,

Peter
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic