File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes ObjectInputStream problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ObjectInputStream problem" Watch "ObjectInputStream problem" New topic
Author

ObjectInputStream problem

Erre ced
Greenhorn

Joined: Sep 29, 2004
Posts: 3
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

Joined: Sep 28, 2004
Posts: 46
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


Author of <a href="http://www.amazon.com/exec/obidos/ASIN/0131482114/ref=jranch-20" target="_blank" rel="nofollow">Just Java(TM) 2 (6th Edition)</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ObjectInputStream problem
 
Similar Threads
De-serialization
Serialization in K&B
IOException while reading objects
Reading Objects and Formatting Ouput
Writing/Reading multiple objects of same class using Serialization?