This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Serialize GUI (Swing)  RSS feed

 
Suletea Dorin
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hy , i have the following issue :
I try to save a JFrame so it's layout and component locations are saved in a configuration file file.







When i try to serialize that frame i get "NotSerializableException" on docker engine thou it's transient (isn't the point of transient to make fields not to be serialized?)

I did try to make that engine implement Serializable interface , then i get

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.plaf.basic.BasicTabbedPaneUI.paint(Unknown Source)
at javax.swing.plaf.ComponentUI.update(Unknown Source)
at javax.swing.JComponent.paintComponent(Unknown Source)
at srcp.ui.docking.DockingTabbedPane.paintComponent(DockingTabbedPane.java:425)

which i have no idea where comes from.

If you have other ideas about how to save that info , any suggestions are welcome.

Cheers mates ,
and Thanks
 
Pierre Sugar
Ranch Hand
Posts: 62
Java Ruby Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DockerEngine is not marked as transient
 
Suletea Dorin
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pierre Sugar wrote:DockerEngine is not marked as transient


I removed it , but with a transient docker engine i get the

java.io.NotSerializableException: srcp.ui.docking.DockerEngine
at java.io.ObjectOutputStream.writeObject0(Unknown Source)

and

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.plaf.basic.BasicTabbedPaneUI.paint(Unknown Source)

ok , second exception i dont know it's source , but the first....
im not serializing it , why does it throw NotSerializableException maybe it's somehow related to the fact that i have a thread inside it (not plausible at all but this is the only thing that makes this class special :P )
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess that the DockerEngine hooks itself somehow into the frame it is used with (most probably it registered itself as a listener somewhere). Even if you declare your reference as transient, it is being serialized due to other references deep in the structure of Swing objects.
 
Suletea Dorin
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting fact :

In my concrete case : BaseForm extends DockingFrame
DockingFrame extends JFrame implements Serializable
agregates DockerEngine


When i serialize new DockingFrame it works
When i serialize BaseForm it fails (like described above)

Any one got a clue why this is happening ?
 
Prabakar Kalivaradan
Greenhorn
Posts: 20
Chrome Eclipse IDE Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Some Serialization basics:

1. Every serialized class should implement either Serializable or Externalizable
2. All non-static non-transient objects members reachable from saved object should be serializable
3. If a class doesn't implement Serializable or Externalizable directly (though its super class implements), any data member that is not serializable will result in NotSerializableException
4. Thread objects are not serializable and any reference by the saved object will cause NotSerializableException
5. Marking a non-serializable field as 'transient' for sure skips it during serialization and should not cause any issues
6. A class should not depend on super classes or subclasses for it's serialization to work properly. It has to take care of everything itself

So, unless you give us the complete source code of the class in question, we can't debug your issue.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!