multithreading - Serialization of chess game logic not succesful after clicking on "save game" button in Java GUI -
i writing quite simple chess game separate gui , logic.the "save game" button starts save filedialog , there user chosen directory , file name passed savegame method in game logic class. there create file fileoutputstream , try write file objectoutputstream. ioexception raised , dont know why.
here snippet of how game class looks, logic part of chess game program.
public class game implements runnable, serializable { private final board board; private final transient moveevaluate moveevaluator; private final logger log = logger.getlogger("game"); private transient boardgui gamegui; private boolean whiteonmove; private boolean gameover = false; private boolean customboardsetup = true; private boolean setupisdone = false; public game() { log.log(level.severe, "game created"); this.board = new board(); this.whiteonmove = true; this.moveevaluator = new moveevaluate(this); }
this save game method whis inside game class. method called gui action click listener.
public void savegame(string directoryname, string filename) { try { fileoutputstream fileout = new fileoutputstream(directoryname+filename+".ser"); objectoutputstream out = new objectoutputstream(fileout); out.writeobject(this); out.close(); catch (ioexception e) { e.printstacktrace(); log.log(level.severe, "exception while serializing : ioexception"); } }
i have in method out.writeobject(this);
of think problem. game class implements runnable.
the question problem . , how handle serialization of logic when gui , logic threads running. thank you
here stack trace ioexception
severe: file crated: c:\users\dagmar kole4k85ov8\desktop\l.ser kv? 29, 2016 10:32:30 dop. com.mycompany.chess.game savegame severe: fileout: c:\users\dagmar kole4k85ov8\desktop\l.ser kv? 29, 2016 10:32:30 dop. com.mycompany.chess.game savegame severe: objectoutputstream made java.io.notserializableexception: java.util.logging.logger @ java.io.objectoutputstream.writeobject0(objectoutputstream.java:1184) @ java.io.objectoutputstream.defaultwritefields(objectoutputstream.java:1548) @ java.io.objectoutputstream.writeserialdata(objectoutputstream.java:1509) @ java.io.objectoutputstream.writeordinaryobject(objectoutputstream.java:1432) @ java.io.objectoutputstream.writeobject0(objectoutputstream.java:1178) @ java.io.objectoutputstream.defaultwritefields(objectoutputstream.java:1548) @ java.io.objectoutputstream.writeserialdata(objectoutputstream.java:1509) @ java.io.objectoutputstream.writeordinaryobject(objectoutputstream.java:1432) @ java.io.objectoutputstream.writeobject0(objectoutputstream.java:1178) @ java.io.objectoutputstream.writeobject(objectoutputstream.java:348) @ com.mycompany.chess.game.savegame(game.java:170) @ com.mycompany.chess.gamegui.savegame(gamegui.java:54) @ com.mycompany.chess.boardmenugui.actionperformed(boardmenugui.java:46) @ javax.swing.abstractbutton.fireactionperformed(abstractbutton.java:2022) @ javax.swing.abstractbutton$handler.actionperformed(abstractbutton.java:2346) @ javax.swing.defaultbuttonmodel.fireactionperformed(defaultbuttonmodel.java:402) @ javax.swing.defaultbuttonmodel.setpressed(defaultbuttonmodel.java:259) @ javax.swing.plaf.basic.basicbuttonlistener.mousereleased(basicbuttonlistener.java:252) @ java.awt.component.processmouseevent(component.java:6525) @ javax.swing.jcomponent.processmouseevent(jcomponent.java:3321) @ java.awt.component.processevent(component.java:6290) @ java.awt.container.processevent(container.java:2234) @ java.awt.component.dispatcheventimpl(component.java:4881) @ java.awt.container.dispatcheventimpl(container.java:2292) @ java.awt.component.dispatchevent(component.java:4703) @ java.awt.lightweightdispatcher.retargetmouseevent(container.java:4898) @ java.awt.lightweightdispatcher.processmouseevent(container.java:4533) @ java.awt.lightweightdispatcher.dispatchevent(container.java:4462) @ java.awt.container.dispatcheventimpl(container.java:2278) @ java.awt.window.dispatcheventimpl(window.java:2739) @ java.awt.component.dispatchevent(component.java:4703) @ java.awt.eventqueue.dispatcheventimpl(eventqueue.java:746) @ java.awt.eventqueue.access$400(eventqueue.java:97) @ java.awt.eventqueue$3.run(eventqueue.java:697) @ java.awt.eventqueue$3.run(eventqueue.java:691) @ java.security.accesscontroller.doprivileged(native method) @ java.security.protectiondomain$1.dointersectionprivilege(protectiondomain.java:75) @ java.security.protectiondomain$1.dointersectionprivilege(protectiondomain.java:86) @ java.awt.eventqueue$4.run(eventqueue.java:719) @ java.awt.eventqueue$4.run(eventqueue.java:717) @ java.security.accesscontroller.doprivileged(native method) @ java.security.protectiondomain$1.dointersectionprivilege(protectiondomain.java:75) @ java.awt.eventqueue.dispatchevent(eventqueue.java:716) @ java.awt.eventdispatchthread.pumponeeventforfilters(eventdispatchthread.java:201) @ java.awt.eventdispatchthread.pumpeventsforfilter(eventdispatchthread.java:116) @ java.awt.eventdispatchthread.pumpeventsforhierarchy(eventdispatchthread.java:105) @ java.awt.eventdispatchthread.pumpevents(eventdispatchthread.java:101) @ java.awt.eventdispatchthread.pumpevents(eventdispatchthread.java:93) @ java.awt.eventdispatchthread.run(eventdispatchthread.java:82) kv? 29, 2016 10:32:30 dop. com.mycompany.chess.game savegame severe: exception while serializing : ioexception
i found mistake myself. problem logger wasn't set transient
@ classes being serialized. after adding transient all, game succesfully saved.
Comments
Post a Comment