• Post Reply Bookmark Topic Watch Topic
  • New Topic

Serialization problem  RSS feed

 
Ivan Demin
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've forgot to tell this is an applet, but I guess it doesn't matter.
 
Paul Clapham
Sheriff
Posts: 22819
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21133
87
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
Ivan Demin
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime, it works! Thanks a lot!
 
Rob Spoor
Sheriff
Posts: 21133
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!