Serializing problem...

Discussion in 'Java' started by Andreas Beresko, Feb 14, 2005.

  1. Hi,

    I'm trying to serialize a JTree and get following error on runtime:

    java.io.NotSerializableException:
    javax.swing.plaf.basic.BasicTextUI$UpdateHandler
    at java.io_ObjectOutputStream.writeObject0(Unknown Source)
    at java.io_ObjectOutputStream.access$100(Unknown Source)
    ....
    at java.io_ObjectOutputStream.writeObject(Unknown Source)
    at javax.swing.tree.DefaultMutableTreeNode.writeObject(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    ....
    at javax.swing.JTree.writeObject(Unknown Source)
    ....

    very suprising: i was able to serialize it with version 1.4.2 but now in
    version 1.5 i can't - a bug???

    best regards
    Andreas
     
    Andreas Beresko, Feb 14, 2005
    #1
    1. Advertising

  2. Andreas Beresko wrote:

    > Hi,
    >
    > I'm trying to serialize a JTree and get following error on runtime:
    >
    > java.io.NotSerializableException:
    > javax.swing.plaf.basic.BasicTextUI$UpdateHandler
    > at java.io_ObjectOutputStream.writeObject0(Unknown Source)
    > at java.io_ObjectOutputStream.access$100(Unknown Source)
    > ...
    > at java.io_ObjectOutputStream.writeObject(Unknown Source)
    > at javax.swing.tree.DefaultMutableTreeNode.writeObject(Unknown Source)
    > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    > at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    > at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    > at java.lang.reflect.Method.invoke(Unknown Source)
    > ...
    > at javax.swing.JTree.writeObject(Unknown Source)
    > ...
    >
    > very suprising: i was able to serialize it with version 1.4.2 but now in
    > version 1.5 i can't - a bug???


    Maybe. JTree implements Serializable, but whether you can serialize a
    particular JTree instance depends also on all the other objects in the
    the JTree's graph. If you have added a non-serializable object directly
    or indirectly to the JTree's model, for instance, then you can expect to
    receive NotSerializableExceptions when you try to serialize the tree.
    Seeing DefaultMutableTreeNode.writeObject() in the stack trace makes me
    think that this is what has happened.

    --
    John Bollinger
     
    John C. Bollinger, Feb 14, 2005
    #2
    1. Advertising

  3. > Maybe. JTree implements Serializable, but whether you can serialize a
    > particular JTree instance depends also on all the other objects in the the
    > JTree's graph. If you have added a non-serializable object directly or
    > indirectly to the JTree's model, for instance, then you can expect to
    > receive NotSerializableExceptions when you try to serialize the tree.
    > Seeing DefaultMutableTreeNode.writeObject() in the stack trace makes me
    > think that this is what has happened.


    I know the mechanism ;-) ... but Iäm wondering why I can serialize my class
    with version 1.4.2 but not with the actual 1.5 ...
    If it is really a bug i need a workaround....
     
    Andreas Beresko, Feb 14, 2005
    #3
  4. Andreas Beresko wrote:

    >>Maybe. JTree implements Serializable, but whether you can serialize a
    >>particular JTree instance depends also on all the other objects in the the
    >>JTree's graph. If you have added a non-serializable object directly or
    >>indirectly to the JTree's model, for instance, then you can expect to
    >>receive NotSerializableExceptions when you try to serialize the tree.
    >>Seeing DefaultMutableTreeNode.writeObject() in the stack trace makes me
    >>think that this is what has happened.

    >
    >
    > I know the mechanism ;-) ... but Iäm wondering why I can serialize my class
    > with version 1.4.2 but not with the actual 1.5 ...
    > If it is really a bug i need a workaround....


    You cannot serialize your class in 1.4.2 either. You don't serialize
    classes at all, only instances. This is why it makes sense to say that
    a class is Serializable but one of its instances cannot be serialized.

    If you want to understand why the problem has arisen then you're going
    to have to dig deeper into your code. _Which_ DefaultMutableTreeNode(s)
    causes the problem? What is its content? That's ultimately where the
    problem is likely to reside. Without more information neither one of us
    can do better than speculate.

    --
    John Bollinger
     
    John C. Bollinger, Feb 15, 2005
    #4
    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. MattB

    problem de-serializing a dataset

    MattB, Apr 27, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    371
    MattB
    Apr 27, 2004
  2. Andreas Beresko

    Serializing problem...

    Andreas Beresko, Jul 12, 2004, in forum: Java
    Replies:
    1
    Views:
    338
    Andreas Beresko
    Jul 12, 2004
  3. Thomas
    Replies:
    2
    Views:
    374
    Thomas
    Sep 2, 2004
  4. sangha
    Replies:
    4
    Views:
    615
    Ashish Pagey
    Mar 8, 2006
  5. Kjetil Orbekk
    Replies:
    4
    Views:
    152
    Robert Klemme
    Dec 26, 2006
Loading...

Share This Page