• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 277
  • Last Modified:

How can we serialize a Frame, and how can we use that again?

 I need to serialize a frame and have to use again it. For that i serialized the frame, but while reading that frame from file, i am getting exception like

 java.io.InvalidClassException: javax.swing.AbstractButton$ButtonActionPropertyChangeListener; no valid constructor
        at java.io.ObjectStreamClass.<init>(ObjectStreamClass.java:428)
        at java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:268)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1029)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:291)
        at java.beans.PropertyChangeSupport.writeObject(PropertyChangeSupport.java:457)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)

 can you suggest me is there any mistake reading the frame from file.
  • 2
2 Solutions
Mayank SAssociate Director - Product EngineeringCommented:
Why is it necessary for you to serialize the frame? The error is for some anonymous inner class defined inside the AbstractButton class. Looks like you serialized it using a different version of Java and are deserializing it using another - just a guess.
To be serializable, ALL classes need to have empty constructors

The inner class ButtonActionPropertyChangeListener does not have an empty constructor

Therefore you can't serialize it.

Try using the XMLEncoder to serialize it if you really need to

But you're probably better off just writing the data to the disk, and writing a method of reloading the data, rather than trying to serialize the UI components

Mayank SAssociate Director - Product EngineeringCommented:
Exactly, you need not serialize the whole frame itself. You can't make changes to the ButtonActionPropertyChangeListener class.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now