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.
krishnasaikarthikAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
TimYatesCommented:
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

Tim

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mayank SAssociate Director - Product EngineeringCommented:
Exactly, you need not serialize the whole frame itself. You can't make changes to the ButtonActionPropertyChangeListener class.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.