java - How to save Object-Lists with ObjectOutputStream and how to read these in? -


i've list "group" objects:

protected static arraylist<gruppe> groups=new arraylist<gruppe>(); 

now want save whole list.

oos.writeobject(groups); 

is correct?
or save each separately?
like this:

for(gruppe g:groups){     oos.writeobject(g);//geht nicht..? } 

and how read in? objectinputstream

groups=(arraylist<gruppe>) ois.readobject(); 

or seperatly again?

groups=new arraylist<gruppe>();  gruppe k=null; while ((k=(gruppe) ois.readobject()) != null) {     groups.add(k); } 

header gruppe:

public class gruppe extends jpanel implements comparable<gruppe>, serializable{ 




save: stacktrace in first way

java.io.notserializableexception: com.sun.java.swing.plaf.windows.xpstyle @ java.io.objectoutputstream.writeobject0(unknown source) @ java.io.objectoutputstream.defaultwritefields(unknown source) @ java.io.objectoutputstream.writeserialdata(unknown source) @ java.io.objectoutputstream.writeordinaryobject(unknown source) @ java.io.objectoutputstream.writeobject0(unknown source) @ java.io.objectoutputstream.defaultwritefields(unknown source) @ java.io.objectoutputstream.writeserialdata(unknown source) @ java.io.objectoutputstream.writeordinaryobject(unknown source) @ java.io.objectoutputstream.writeobject0(unknown source) @ java.io.objectoutputstream.defaultwritefields(unknown source) @ java.io.objectoutputstream.defaultwriteobject(unknown source) @ javax.swing.jcomponent.writeobject(unknown source) @ sun.reflect.generatedmethodaccessor10.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ java.io.objectstreamclass.invokewriteobject(unknown source) @ java.io.objectoutputstream.writeserialdata(unknown source) @ java.io.objectoutputstream.writeordinaryobject(unknown source) @ java.io.objectoutputstream.writeobject0(unknown source) @ java.io.objectoutputstream.writearray(unknown source) @ java.io.objectoutputstream.writeobject0(unknown source) @ java.io.objectoutputstream.access$300(unknown source) @ java.io.objectoutputstream$putfieldimpl.writefields(unknown source) @ java.io.objectoutputstream.writefields(unknown source) @ java.awt.container.writeobject(unknown source) @ sun.reflect.generatedmethodaccessor9.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ java.io.objectstreamclass.invokewriteobject(unknown source) @ java.io.objectoutputstream.writeserialdata(unknown source) @ java.io.objectoutputstream.writeordinaryobject(unknown source) @ java.io.objectoutputstream.writeobject0(unknown source) @ java.io.objectoutputstream.writearray(unknown source) @ java.io.objectoutputstream.writeobject0(unknown source) @ java.io.objectoutputstream.access$300(unknown source) @ java.io.objectoutputstream$putfieldimpl.writefields(unknown source) @ java.io.objectoutputstream.writefields(unknown source) @ java.awt.container.writeobject(unknown source) @ sun.reflect.generatedmethodaccessor9.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ java.io.objectstreamclass.invokewriteobject(unknown source) @ java.io.objectoutputstream.writeserialdata(unknown source) @ java.io.objectoutputstream.writeordinaryobject(unknown source) @ java.io.objectoutputstream.writeobject0(unknown source) @ java.io.objectoutputstream.writearray(unknown source) @ java.io.objectoutputstream.writeobject0(unknown source) @ java.io.objectoutputstream.access$300(unknown source) @ java.io.objectoutputstream$putfieldimpl.writefields(unknown source) @ java.io.objectoutputstream.writefields(unknown source) @ java.awt.container.writeobject(unknown source) @ sun.reflect.generatedmethodaccessor9.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ java.io.objectstreamclass.invokewriteobject(unknown source) @ java.io.objectoutputstream.writeserialdata(unknown source) @ java.io.objectoutputstream.writeordinaryobject(unknown source) @ java.io.objectoutputstream.writeobject0(unknown source) @ java.io.objectoutputstream.writearray(unknown source) @ java.io.objectoutputstream.writeobject0(unknown source) @ java.io.objectoutputstream.access$300(unknown source) @ java.io.objectoutputstream$putfieldimpl.writefields(unknown source) @ java.io.objectoutputstream.writefields(unknown source) @ java.awt.container.writeobject(unknown source) @ sun.reflect.generatedmethodaccessor9.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ java.io.objectstreamclass.invokewriteobject(unknown source) @ java.io.objectoutputstream.writeserialdata(unknown source) @ java.io.objectoutputstream.writeordinaryobject(unknown source) @ java.io.objectoutputstream.writeobject0(unknown source) @ java.io.objectoutputstream.writearray(unknown source) @ java.io.objectoutputstream.writeobject0(unknown source) @ java.io.objectoutputstream.access$300(unknown source) @ java.io.objectoutputstream$putfieldimpl.writefields(unknown source) @ java.io.objectoutputstream.writefields(unknown source) @ java.awt.container.writeobject(unknown source) @ sun.reflect.generatedmethodaccessor9.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ java.io.objectstreamclass.invokewriteobject(unknown source) @ java.io.objectoutputstream.writeserialdata(unknown source) @ java.io.objectoutputstream.writeordinaryobject(unknown source) @ java.io.objectoutputstream.writeobject0(unknown source) @ java.io.objectoutputstream.writearray(unknown source) @ java.io.objectoutputstream.writeobject0(unknown source) @ java.io.objectoutputstream.access$300(unknown source) @ java.io.objectoutputstream$putfieldimpl.writefields(unknown source) @ java.io.objectoutputstream.writefields(unknown source) @ java.awt.container.writeobject(unknown source) @ sun.reflect.generatedmethodaccessor9.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ java.io.objectstreamclass.invokewriteobject(unknown source) @ java.io.objectoutputstream.writeserialdata(unknown source) @ java.io.objectoutputstream.writeordinaryobject(unknown source) @ java.io.objectoutputstream.writeobject0(unknown source) @ java.io.objectoutputstream.defaultwritefields(unknown source) @ java.io.objectoutputstream.writeserialdata(unknown source) @ java.io.objectoutputstream.writeordinaryobject(unknown source) @ java.io.objectoutputstream.writeobject0(unknown source) @ java.io.objectoutputstream.writeobject(unknown source) @ java.awt.awteventmulticaster.save(unknown source) @ java.awt.component.writeobject(unknown source) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ java.io.objectstreamclass.invokewriteobject(unknown source) @ java.io.objectoutputstream.writeserialdata(unknown source) @ java.io.objectoutputstream.writeordinaryobject(unknown source) @ java.io.objectoutputstream.writeobject0(unknown source) @ java.io.objectoutputstream.writeobject(unknown source) @ java.util.arraylist.writeobject(unknown source) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ java.io.objectstreamclass.invokewriteobject(unknown source) @ java.io.objectoutputstream.writeserialdata(unknown source) @ java.io.objectoutputstream.writeordinaryobject(unknown source) @ java.io.objectoutputstream.writeobject0(unknown source) @ java.io.objectoutputstream.writeobject(unknown source) @ ralaprogramme.occupancyoverview.filesave(occupancyoverview.java:542) @ ralaprogramme.occupancyoverview.action_menubar(occupancyoverview.java:298) @ ralaprogramme.occupancyoverview.actionperformed(occupancyoverview.java:260) @ javax.swing.abstractbutton.fireactionperformed(unknown source) @ javax.swing.abstractbutton$handler.actionperformed(unknown source) @ javax.swing.defaultbuttonmodel.fireactionperformed(unknown source) @ javax.swing.defaultbuttonmodel.setpressed(unknown source) @ javax.swing.abstractbutton.doclick(unknown source) @ javax.swing.plaf.basic.basicmenuitemui.doclick(unknown source) @ javax.swing.plaf.basic.basicmenuitemui$handler.mousereleased(unknown source) @ java.awt.component.processmouseevent(unknown source) @ javax.swing.jcomponent.processmouseevent(unknown source) @ java.awt.component.processevent(unknown source) @ java.awt.container.processevent(unknown source) @ java.awt.component.dispatcheventimpl(unknown source) @ java.awt.container.dispatcheventimpl(unknown source) @ java.awt.component.dispatchevent(unknown source) @ java.awt.lightweightdispatcher.retargetmouseevent(unknown source) @ java.awt.lightweightdispatcher.processmouseevent(unknown source) @ java.awt.lightweightdispatcher.dispatchevent(unknown source) @ java.awt.container.dispatcheventimpl(unknown source) @ java.awt.window.dispatcheventimpl(unknown source) @ java.awt.component.dispatchevent(unknown source) @ java.awt.eventqueue.dispatcheventimpl(unknown source) @ java.awt.eventqueue.access$200(unknown source) @ java.awt.eventqueue$3.run(unknown source) @ java.awt.eventqueue$3.run(unknown source) @ java.security.accesscontroller.doprivileged(native method) @ java.security.protectiondomain$1.dointersectionprivilege(unknown source) @ java.security.protectiondomain$1.dointersectionprivilege(unknown source) @ java.awt.eventqueue$4.run(unknown source) @ java.awt.eventqueue$4.run(unknown source) @ java.security.accesscontroller.doprivileged(native method) @ java.security.protectiondomain$1.dointersectionprivilege(unknown source) @ java.awt.eventqueue.dispatchevent(unknown source) @ java.awt.eventdispatchthread.pumponeeventforfilters(unknown source) @ java.awt.eventdispatchthread.pumpeventsforfilter(unknown source) @ java.awt.eventdispatchthread.pumpeventsforhierarchy(unknown source) @ java.awt.eventdispatchthread.pumpevents(unknown source) @ java.awt.eventdispatchthread.pumpevents(unknown source) @ java.awt.eventdispatchthread.run(unknown source) 

write whole list @ once. if write each group seperately, you'll have read them in loop until exception, or you'll have send number of groups before sending groups know how many groups read. sending list easier.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -