0
   

help(Java) I'm getting following error:

 
 
Reply Fri 16 Mar, 2012 05:48 am
help(Java) I'm getting following error:

Exception in thread "main" java.io.InvalidClassException: Viikko; local class in
compatible: stream classdesc serialVersionUID = 4612314676209207182, local class
serialVersionUID = -1307850474070120741
at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:562)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:158
2)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1495)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1
731)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1666)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1322)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:19
46)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1870)

at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1
752)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
at LueBin.lueOlio(LueBin.java:48)
at LukujarjestysPaa.main(LukujarjestysPaa.java:20)

This happened when I removed a parameter from one method which was not needed in that method, because it didn't use that parameter.
  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Question • Score: 0 • Views: 2,372 • Replies: 2
No top replies

 
silversturm
 
  0  
Reply Fri 16 Mar, 2012 11:28 pm
@alvoutila,
When you serialize a Serializable object out to disk, it will be written with a special piece of data called the serialVersionUID. It is recommended that you provide this field yourself in the class, but if you don't have one, one will be generated for you. The purpose of the class is to make sure that the object that is saved to disk is still compatible with the class definition loaded in the Java Virtual Machine at run time. In other words, let's say yesterday I had a class:

public class Dog implements Serializable {
String name;
int age;
}

and I wrote a few Dog objects out to disk. But then today I changed the class to

public class Dog implements Serializable {
float weight;
int age;
}

Well, I can't very well read those previous Dog objects off of disk and load them into my currently-running program because the definition of Dog has changed. So yes, most likely, changes you made to your class have made it incompatible with some sort of previously-saved (to disk) instances of the class. It's possible if you are not providing the serialVersionUID field, then the automatically-generated one is being changed by the JVM just because you changed that method's parameters.

This may help some: http://www.mkyong.com/java-best-practices/understand-the-serialversionuid/
Or the official Java Doc on the subject:
http://docs.oracle.com/javase/1.5.0/docs/api/java/io/Serializable.html
"If the receiver has loaded a class for the object that has a different serialVersionUID than that of the corresponding sender's class, then deserialization will result in an InvalidClassException."
0 Replies
 
alvoutila
 
  1  
Reply Sun 18 Mar, 2012 12:43 pm
I fixed it when I just made necessary changes and then just called new binary file as args[0] in the calling of my main program( eq. java Main bin.dat) and not the old one. Then program run well without this error that I wrote here. So it was because I used old binary file while updating the program and it resulted as the error.
0 Replies
 
 

Related Topics

Clone of Micosoft Office - Question by Advocate
Do You Turn Off Your Computer at Night? - Discussion by Phoenix32890
The "Death" of the Computer Mouse - Discussion by Phoenix32890
Windows 10... - Discussion by Region Philbis
Surface Pro 3: What do you think? - Question by neologist
Windows 8 tips thread - Discussion by Wilso
GOOGLE CHROME - Question by Setanta
.Net and Firefox... - Discussion by gungasnake
Hacking a computer and remote access - Discussion by trying2learn
 
  1. Forums
  2. » help(Java) I'm getting following error:
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.41 seconds on 12/21/2024 at 08:01:49