주로 JTree 및 일부 다른 구성 요소가 포함 된 스윙 응용 프로그램을 작성하고 있습니다. UI 디스플레이 뒤의 완전한 로직은 JTree의 루트 노드를 기반으로합니다. 이 노드는 각 사용자 노드에 개별 사용자 정의 사용자 객체가 설정된 중첩 노드입니다.JTree (groovy/java)의 루트 노드를 직렬화 할 수 없습니다.
JTree의 단일 중첩 루트 노드를 보존해야하는 내 응용 프로그램의 상태를 유지해야합니다. 나는 그렇게 할 수 없다. doSerialize()
방법은 news.txt
파일 위에 뭔가를 쓰기 않습니다하지만 나는 그것이 직렬화 경우 잘 모르겠습니다 ..
class SerializeImpl implements Serializable{
def doSerialize() throws Exception{
def root = FeedTree.getInstance().getModel().getRoot()
def object = new SerializableNode(top:root)
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("new.txt"))
out.writeObject(object)
}
def doDeSerialize(){
def file = new File('new.txt')
def serNodeObj
try{
file.withObjectInputStream(getClass().classLoader){ ois ->
ois.eachObject{ serNodeObj = it }
}
return serNodeObj.getValue()
}
catch(FileNotFoundException ex){
return null
}
}
}
class SerializableNode implements Serializable{
def top
def getValue(){
return top
}
}
class FeedTree extends JTree{
...............
a singleton instance
...............
}
doSerialize()
방법은 먼저 System.exit(1)
다음에 실행되고 doDeSerialize()
을 수행 UI의 새로운 표시 다음에 개체가 올바르게 또한 직렬화 후 System.exit(1)
이 작동하지 않습니다.
doDeSerialize()
의 첫 실행은 강제 종료 (Eclipse 콘솔에서 종료) 후 다음 예외를 발생시킵니다.
Caught: java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: groovy.util.slurpersupport.NodeChildren
at functionalities.SerializeImpl$_doDeSerialize_closure1.doCall(SerializeImpl.groovy:23)
at functionalities.SerializeImpl.doDeSerialize(SerializeImpl.groovy:22)
은 내가 직렬화가 이유를 이해 할 수없는 오전 (아마) 실패하고 왜 System.exit(1)
은 직렬화 후 제대로 작동하지 않습니다. 도와주세요.
내 생각에
TreeNodes
래핑 추가 이것은 내가 필요한 것에 가깝다. 클리어를 설명해 주시겠습니까? –