wood burning stoves 2.0*
The moose likes I/O and Streams and the fly likes Serialization thingymabob??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Serialization thingymabob???" Watch "Serialization thingymabob???" New topic
Author

Serialization thingymabob???

Cathal McNally
Greenhorn

Joined: Nov 27, 2010
Posts: 4
Hey JavaRanch,
Big fan of the forum and ive solved many issues from trolling through your collection.
Unfortunately ive come across one i cant solve.
I have an Assignment Due this Thursday concerning this code and i get this weird error

Basically this is what ive got

I have a bunch of classes
Person
Employee
EmployeeFilehandler
EmployeeTester
Menu

Employee extends Person and implements Serializable

Ok here is my file handler code that think the issue resides.


The error i get is as follows

Employee; local class incompatible: stream classdesc serialVersionUID = 45211, local class serialVersionUID = 3434283155416449586

Now the reason the serialVersionUID = 45211 is "45211" because i originally randomly defined it at the start of the file but have since removed it and it seems to want to stay

I really do appreciate any help guys

Thanks
Cathal
Aka FooFighter
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
For starters, if a class "implements Serializable", then it should define an explicit serialVersionUID; that's just good practice. The question is: does this class (or its superclass) need to implement that interface? There seems to be no code doing any serialization.

Where (and when) are you getting that message? I'd say you have old class file around somewhere that still have the previous serialVersionUID.
Cathal McNally
Greenhorn

Joined: Nov 27, 2010
Posts: 4
Sorry this here is the EmployeeFileHandler.java


I think i meant to upload this the first time
writeRecordsToFile() is meant to write the employee arraylist to a file
where readRecordsFromFile() is meant to take it back in

Maybe someone with some time can compile and see what the issue is im having?

it can be downloaded here
http://cathalmcnally.wikispaces.com/file/view/java.zip

I really appreciate it guys
Thank you
Cathal
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
OK, so the code *is* doing serialization. First question: has the file it's reading from been created by an older version? That would be a problem. Second question: do you have old class files somewhere in your classpath?
Cathal McNally
Greenhorn

Joined: Nov 27, 2010
Posts: 4
Hey
No i deleted the class files and i still get the error

Also i deleted the .bin file and recompiled and ran it
got this


"Employee.bin (The system cannot find the file specified)"
Not sure whats up


Thanks for helping



Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Also i deleted the .bin file and recompiled and ran it
got this

"Employee.bin (The system cannot find the file specified)"

You didn't post the code that calls the readRecordsFromFile and writeRecordsToFile methods, but it sounds as if you're trying to read the file before it is created.
Cathal McNally
Greenhorn

Joined: Nov 27, 2010
Posts: 4
hey
sorry about that...
Um here is my tester


Can i just say that i got this working before with a different class and all ive really done is copied my last assignment and changed the Names
All the code is here
You might understand better through compilation
http://cathalmcnally.wikispaces.com/file/view/java.zip
Anyway
Thanks
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
OK, so you *are* reading a file that doesn't exist. That means the line you're seeing is printed by the exception handler of the readRecordsFromFile method. So all should be well.

It'd be more elegant to use File.exists() to check whether the file exists, and not try to open it blindly.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Serialization thingymabob???
 
Similar Threads
Precise age calculation..
Inheritence query??
java.lang.NumberFormatException: For input string: ""
Problem with Date
[error] Exception in thread "main" java.lang.NullPointerException