Link to home
Start Free TrialLog in
Avatar of islandguy10
islandguy10

asked on

Urgent-Errors with Serialization

This is a school assignment so I just want some direction.  I really need some help with serialization. I've read all the java sources and looked at many examples and I feel like I've been doing everything properly but whatever I try it seems that I still get a java.io.NotSerializableException.  Could someone point out where I am going wrong here?  My two important classes are attached.  Thanks!
TestLibGUI.java
Library.java
Avatar of Mick Barry
Mick Barry
Flag of Australia image

you didn't post Book class, make sure it is Serializable
Avatar of islandguy10
islandguy10

ASKER

Ok, I attached it.  Books is Serializable, as are these other two classes Title, and Borrower.  I have some exception classes as well which all implement Serializable as well.
Book.java
Title.java
Borrower.java
NotSerializableException is usually constructed with the name of the offending class as the message. What value is returned when you call toString() on the exception?
This is what I see in the NetBeans display.  But, I'm not sure exactly where or what is causing the exception.

java.io.NotSerializableException: TestLibGUI$6
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1156)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1509)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1474)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
        at java.util.HashMap.writeObject(HashMap.java:1001)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
"TestLibGUI$6" means "the sixth anonymous nested class in TestLibGUI. I'll bet it's choking on your various ActionListeners and MouseListeners.

After refreshing this question, I see objects has pointed out the likely culprit. Try taking out the empty braces after the Book constructor.
That was it!  Thanks a lot!...I'm new to this site still and I think I missed the part where I can split the points. :/  Your comments were very helpful as well CPColin.  My head feels a lot better now!!!!!