1
적의 ArrayList가 포함 된 게임 객체를 직렬화하여 게임 상태를 저장하려고합니다. ArrayList의 각 아이템은 오브젝트이며, 각 오브젝트에는 적을 나타내는 BufferedImage가 포함되어 있습니다. Java는 BufferedImages가 직렬화 가능하지 않다는 오류를 발생시킵니다. 내가 발견 한 모든 솔루션은 이미지를 제외한 모든 데이터로 새로운 개체를 작성한다고하지만 List를 설정하는 것이 가능한지 확실하지 않습니다.BufferedImages를 사용하여 객체의 ArrayList를 직렬화하기
public void saveGame(){
GamePanel game = new GamePanel();
game.enemyList = enemyList;
game.player = new Player(this.getWidth(), this.getHeight());
game.player.setScore(player.getScore());
game.player.setPos(player.getX(), player.getY());
try{
FileOutputStream fileOut = new FileOutputStream("savegame.txt");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(game);
out.close();
fileOut.close();
}catch(IOException ex){
ex.printStackTrace();
}
}
감사합니다.
'일시적'으로 직렬화하지 않으려는 속성을 표시하십시오. V.g.,'private transient BufferedImage alienImage; – SJuan76
완벽하게 작동합니다. 정말 고마워요! – cogm
답변이 있어야합니다. – ksmonkey123