File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Serialization problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Serialization problem" Watch "Serialization problem" New topic
Author

Serialization problem

Ivan Demin
Greenhorn

Joined: Dec 21, 2010
Posts: 5
Hi there!

Here's my class:


I successfully serialize SBufferedImage object, but then i try this to deserialize:


and I receive this error: "java.io.InvalidClassException: SBufferedImage; SBufferedImage; no valid constructor"

I know that it is required for deserialized object to have default constructor but it has one. What am i doing wrong?

Ivan Demin
Greenhorn

Joined: Dec 21, 2010
Posts: 5
I've forgot to tell this is an applet, but I guess it doesn't matter.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16482
    
    2

Ivan Demin wrote:I've forgot to tell this is an applet, but I guess it doesn't matter.


No, I don't think it matters either. So let's move the thread...
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

For a class to be serializable, its super class must a) be serializable too, or b) it must have a no-argument constructor. Unfortunately for you, BufferedImage does not meet these criteria. Therefore, you can't (easily) serialize / deserialize your class.

There is good news though. Class ImageIO allows you to read a BufferedImage from any InputStream, and write a BufferedImage with a specific type (e.g. JPG, PNG) to any OutputStream. Maybe you can use that for the "serialization" / "deserialization".


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Ivan Demin
Greenhorn

Joined: Dec 21, 2010
Posts: 5
Rob Prime wrote:For a class to be serializable, its super class must a) be serializable too, or b) it must have a no-argument constructor. Unfortunately for you, BufferedImage does not meet these criteria. Therefore, you can't (easily) serialize / deserialize your class.

There is good news though. Class ImageIO allows you to read a BufferedImage from any InputStream, and write a BufferedImage with a specific type (e.g. JPG, PNG) to any OutputStream. Maybe you can use that for the "serialization" / "deserialization".


Thanks, i'll try that.
Ivan Demin
Greenhorn

Joined: Dec 21, 2010
Posts: 5
Rob Prime, it works! Thanks a lot!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

You're welcome
 
I agree. Here's the link: http://jrebel.com/download
 
subject: Serialization problem
 
Similar Threads
Deserialization issue if I have serialized object to ByteArrayOutputStream
Threads,serialisation, static variables - java basic doubts
In how many ways we can create an object? could you Explain with example if possible.
Inheritance and Serialization
Serialszing method of superclass which is non serilizable