I saved an ArrayList<MyClass>
as object with an ObjectOutputStream
. Now, how can I read that object on my another application project with a ObjectInputStream
? I tried and it throws an ClassNotFoundException
. I have copied MyClass
from project 1 to project 2. Do I have to do anything else?
You should not copy a class and the expect that it looks the same - the Java Compiler / the JVM notices the changes. Use exactly the same class file!!!
There are several versions to do so:
MyClass
And what you never should forgett: Every Serializable
should have a serialVersionUID
Eclipse automatically makes a warning - click on it and generate it. If you don't have Eclipse, use serialver
from the JDK.
But don't forget: If your class changed so that old versions won't be interpretable by new versions, change the serialversionUID
.