Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2006

Tip: Looking for answers? Try searching our database.

writeObject IOException

Thread view: 
javafan - 01 Sep 2006 16:16 GMT
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
Thomas Hawtin - 01 Sep 2006 17:48 GMT
> 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
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

javafan - 01 Sep 2006 21:52 GMT
but why I get such an exception when I just try to convert to bytes Hashmap
which contains simple objects.
Piotr Kobzda - 01 Sep 2006 22:19 GMT
> 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
Thomas Hawtin - 01 Sep 2006 22:33 GMT
> 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
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

javafan - 02 Sep 2006 09:25 GMT
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
Thomas Hawtin - 02 Sep 2006 15:16 GMT
> As I know String and char are serializable and these are the only fields in
> my class:
[quoted text clipped - 5 lines]
>  
>         ...//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());
    }
}
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

javafan - 02 Sep 2006 17:20 GMT
Thanks for help Thomas. Now when my class isn't inner everything seems to
work well :)

Rgds.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.