writeObject IOException

Discussion in 'Java' started by javafan, Sep 1, 2006.

  1. javafan

    javafan Guest

    Hi,

    I'm trying to develop the application which uses writeObject method to
    write Hashtable but after procedure toBytes calling I get the exception:

    SEVERE: org.jdesktop.layout.GroupLayout

    Here is the code of toBytes procedure:

    public static byte[] toBytes(Object object){
    java.io.ByteArrayOutputStream baos = new
    java.io.ByteArrayOutputStream();
    try{
    java.io_ObjectOutputStream oos = new
    java.io_ObjectOutputStream(baos);
    oos.writeObject(object);
    } catch(java.io.IOException ioe) {
    System.err.println("error");

    java.util.logging.Logger.global.log(java.util.logging.Level.SEVERE,
    ioe.getMessage());
    }
    return baos.toByteArray();
    }

    Thanks in advance for any help,
    Paul
     
    javafan, Sep 1, 2006
    #1
    1. Advertising

  2. javafan wrote:
    >
    > I'm trying to develop the application which uses writeObject method to
    > write Hashtable but after procedure toBytes calling I get the exception:
    >
    > SEVERE: org.jdesktop.layout.GroupLayout


    GroupLayout in Mustang is not serialisable. Presumably it isn't in
    org.jdesktop either.

    Tom Hawtin
    --
    Unemployed English Java programmer
    http://jroller.com/page/tackline/
     
    Thomas Hawtin, Sep 1, 2006
    #2
    1. Advertising

  3. javafan

    javafan Guest

    but why I get such an exception when I just try to convert to bytes Hashmap
    which contains simple objects.
     
    javafan, Sep 1, 2006
    #3
  4. javafan

    Piotr Kobzda Guest

    javafan wrote:

    > but why I get such an exception when I just try to convert to bytes Hashmap
    > which contains simple objects.


    At least one of them is probably too simple. All objects being
    serialized (all your map elements) must be serializable.


    piotr
     
    Piotr Kobzda, Sep 1, 2006
    #4
  5. javafan wrote:
    > but why I get such an exception when I just try to convert to bytes Hashmap
    > which contains simple objects.


    It looks as if it isn't just "simple" objects. If you open the file in a
    suitable text editor, you should see the names of the classes it contains.

    Tom Hawtin
    --
    Unemployed English Java programmer
    http://jroller.com/page/tackline/
     
    Thomas Hawtin, Sep 1, 2006
    #5
  6. javafan

    javafan Guest

    As I know String and char are serializable and these are the only fields in
    my class:

    public class Person implements Serializable {
    private String id;
    private String unit;
    private char[] code;

    ...//methods
     
    javafan, Sep 2, 2006
    #6
  7. javafan wrote:
    > As I know String and char are serializable and these are the only fields in
    > my class:
    >
    > public class Person implements Serializable {
    > private String id;
    > private String unit;
    > private char[] code;
    >
    > ...//methods


    Your program is not doing what you expect. Therefore it seems likely
    that at least one thing you know to be true about it is wrong. For
    instance, perhaps you have an inner class which will attempt to
    serialise the outer instance.

    There are lots of fun things with ObjectOutputStream. For instance the
    code below prints the class of objects that are written to the stream.
    In the case below you see the object we are interested in, its simple
    field and then the outer instance (followed by an exception).

    Tom Hawtin


    import java.io.*;

    class Write {
    public class SimpleThing implements Serializable {
    private final String simpleField = "My simple field";
    }

    public static void main(String[] args) throws Exception {
    new Write().write();
    }
    private void write() throws Exception {
    ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(byteOut) {
    {
    enableReplaceObject(true);
    }
    @Override
    protected Object replaceObject(
    Object obj
    ) throws IOException {
    System.err.println(
    obj==null ? null : obj.getClass()
    );
    return super.replaceObject(obj);
    }
    };
    out.writeObject(new SimpleThing());
    }
    }
    --
    Unemployed English Java programmer
    http://jroller.com/page/tackline/
     
    Thomas Hawtin, Sep 2, 2006
    #7
  8. javafan

    javafan Guest

    SOLVED

    Thanks for help Thomas. Now when my class isn't inner everything seems to
    work well :)

    Rgds.
     
    javafan, Sep 2, 2006
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kaidi
    Replies:
    4
    Views:
    2,484
    Kaidi
    Jan 3, 2004
  2. Kaidi
    Replies:
    7
    Views:
    4,515
    Robert Olofsson
    Jan 6, 2004
  3. JMC
    Replies:
    1
    Views:
    803
    Roedy Green
    Apr 7, 2004
  4. jprogrammer
    Replies:
    10
    Views:
    5,173
    Tony Morris
    Apr 22, 2004
  5. Roedy Green

    writeObject signature

    Roedy Green, Jun 8, 2004, in forum: Java
    Replies:
    35
    Views:
    1,294
    Dale King
    Apr 15, 2006
Loading...

Share This Page