Serialisierung schlägt fehl

lazydog

Mitglied
Hallo,

ich versuche, ein etwas komplexeres Objekt zu serialisieren, scheitere bei der Ausführung von
Code:
myObjectOutputStream.writeObject(myObject);
aber an folgender Exception:
Code:
java.io.NotSerializableException: java.awt.EventQueue
	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.writeArray(ObjectOutputStream.java:1338)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1146)
	at java.io.ObjectOutputStream.access$300(ObjectOutputStream.java:143)
	at java.io.ObjectOutputStream$PutFieldImpl.writeFields(ObjectOutputStream.java:1668)
	at java.io.ObjectOutputStream.writeFields(ObjectOutputStream.java:454)
	at java.awt.Container.writeObject(Container.java:3548)
	at sun.reflect.GeneratedMethodAccessor15.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:945)
	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1461)
	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
	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.writeArray(ObjectOutputStream.java:1338)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1146)
	at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1509)
	at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:416)
	at java.util.Vector.writeObject(Vector.java:1012)
	at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:945)
	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1461)
	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
	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 javax.swing.event.EventListenerList.writeObject(EventListenerList.java:240)
	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:597)
	at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:945)
	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1461)
	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
	at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1509)
	at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:416)
	at javax.swing.JComponent.writeObject(JComponent.java:5429)
	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:597)
	at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:945)
	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1461)
	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
	at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1338)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1146)
	at java.io.ObjectOutputStream.access$300(ObjectOutputStream.java:143)
	at java.io.ObjectOutputStream$PutFieldImpl.writeFields(ObjectOutputStream.java:1668)
	at java.io.ObjectOutputStream.writeFields(ObjectOutputStream.java:454)
	at java.awt.Container.writeObject(Container.java:3548)
	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:597)
	at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:945)
	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1461)
	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
	at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1338)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1146)
	at java.io.ObjectOutputStream.access$300(ObjectOutputStream.java:143)
	at java.io.ObjectOutputStream$PutFieldImpl.writeFields(ObjectOutputStream.java:1668)
	at java.io.ObjectOutputStream.writeFields(ObjectOutputStream.java:454)
	at java.awt.Container.writeObject(Container.java:3548)
	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:597)
	at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:945)
	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1461)
	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.awt.AWTEventMulticaster.save(AWTEventMulticaster.java:929)
	at java.awt.Component.writeObject(Component.java:8350)
	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:597)
	at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:945)
	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1461)
	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 src.jadiscore.CoreApplet.storePersistable(CoreApplet.java:329)
	at src.jadiscore.CoreApplet.storePersistables(CoreApplet.java:254)
	at src.jadiscore.CoreApplet.stop(CoreApplet.java:166)
	at sun.applet.AppletPanel.run(AppletPanel.java:525)
	at java.lang.Thread.run(Thread.java:619)
Ich habe keine Ahnung, an welcher Stelle der Hierarchie diese geworfen wird und damit die Fehlerquelle zu suchen ist - "Serializable" ist eigentlich überall implementiert! Hat da irgendjemand einen Tipp

vielen Dank im voraus
 
Du hältst in einem Objekt das du serialisieren willst entweder direkt oder transitiv eine Referenz auf eine Klasse aus java.awt, die eben nicht serialisierbar ist.

Gruß
Ollie
 
Hallo Ollie,

vielen Dank für die Antwort! Soweit ist das schon klar - das Problem ist: wie finde ich die Stelle?

Nein Problem war ja in erster Linie, dass anhand des Stacktrace nicht ersichtlich war, welches Objekt dasProblem verursacht. Abhilfe kann hier durch:
Code:
System.setProperty("sun.io.serialization.extendedDebugInfo", "true");
geschaffen werden. Die Ausgabe ist dann etwas wortreicher.

vielen Dank trotzdem für die Hilfe!

Gruß
Lazydog
 
Zurück