writeObject IOException

J

javafan

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
 
T

Thomas Hawtin

javafan said:
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
 
J

javafan

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

Piotr Kobzda

javafan said:
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
 
T

Thomas Hawtin

javafan said:
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
 
J

javafan

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
 
T

Thomas Hawtin

javafan said:
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());
}
}
 
J

javafan

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

Rgds.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top