| 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
|
|
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
|
 |
 |
|
|
subject: Serialization problem
|
|
|