Serializing problem...

A

Andreas Beresko

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
 
J

John C. Bollinger

Andreas said:
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.
 
A

Andreas Beresko

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....
 
J

John C. Bollinger

Andreas said:
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.
 

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,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top