且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用ObjectInputStream从文件加载保存的游戏

更新时间:2023-02-02 18:33:46

@Humakt


Care to el对问题有所了解?它不是从Stream中读取对象吗?确保Game对象的所有成员对象都是Serializable或使它们成为瞬态。


顺便说一下,如果您使用的IDE最有可能为您生成VersionID值。


亲切的问候,


Jos
@Humakt
Care to elaborate a bit on the ''bit of a problem''? Doesn''t it read the object from the Stream? Make sure that all your member objects of a Game object are Serializable or make them transient.

btw, if you''re using an IDE most likely it can generate a VersionID value for you.

kind regards,

Jos


@JOSAH


嗯,我认为问题在于文件中有多个对象,但它们都是这个游戏对象的一部分(单向或其他)。我尝试在循环中读取对象,但它也返回null。


我在第二个句子中更正了第一个帖子。


这是函数我用来写对象:

@JosAH
Well, I think the problem is that there are multiple objects in the file, but they are all (one way or other) part of this game object. I tried reading object in loop as well but it also returned null.

I correct the first post in sec.

This is the function I use to write the object:

展开 | 选择 | Wrap | 行号


@Humakt >

对于调试,使所有成员对象成为瞬态并再试一次;你应该能够写/读一个(几乎)空的Game对象。接下来再次添加成员对象并为其提供另一个SerialVersionUID编号,然后重试。你的代码看起来很合理。


亲切的问候,


Jos
@Humakt
For debugging make all your member objects transient and try again; you should be able to write/read an (almost) empty Game object. Next add the member objects again and give them another SerialVersionUID number and try again. Your code looks reasonable.

kind regards,

Jos