Duplicate :
|
Though the documentation says Image is Serializable, it is in fact not so because it contains objects which are not serializable. Here is a small test case which shows the bug (modify the test to supply a .gif file). This bug critically impacts core functionality of Java Studio. abhilasha{pjajoo}256: cat ImageBug.java import java.awt.*; import java.io.*; public class ImageBug { public static void main(String[] args) { Image img = Toolkit.getDefaultToolkit().getImage("Button.gif"); System.out.println("Img = " + img); try { ObjectOutputStream os = new ObjectOutputStream( new ByteArrayOutputStream()); os.writeObject(img); os.close(); } catch (Exception e) { e.printStackTrace(System.out); } } } abhilasha{pjajoo}257: javac ImageBug.java abhilasha{pjajoo}261: java ImageBug Img = sun.awt.motif.X11Image@1dae07cc java.io.NotSerializableException: sun.awt.image.ImageInfoGrabber at java.lang.Throwable.<init>(Compiled Code) at java.lang.Exception.<init>(Compiled Code) at java.io.IOException.<init>(Compiled Code) at java.io.ObjectStreamException.<init>(Compiled Code) at java.io.NotSerializableException.<init>(Compiled Code) at java.io.ObjectOutputStream.outputObject(Compiled Code) at java.io.ObjectOutputStream.writeObject(Compiled Code) at java.io.ObjectOutputStream.defaultWriteObject(Compiled Code) at java.io.ObjectOutputStream.outputObject(Compiled Code) at java.io.ObjectOutputStream.writeObject(Compiled Code) at ImageBug.main(Compiled Code)