使用枚举字段序列化对象时的java.io.StreamCorruptedException

时间:2014-05-12 10:08:22

标签: java android serialization enums

我使用序列化在Android中的服务和应用程序之间进行互连。 我得到了不稳定的异常java.io.StreamCorruptedException。 Android 4.1.2,here是ObjectInputStream.java,对应这个版本的Android。

Caused by: java.io.StreamCorruptedException: Wrong format: 0
at java.io.ObjectInputStream.corruptStream(ObjectInputStream.java:701)
at java.io.ObjectInputStream.readContent(ObjectInputStream.java:749)
at java.io.ObjectInputStream.discardData(ObjectInputStream.java:662)
at java.io.ObjectInputStream.readEnumDescInternal(ObjectInputStream.java:1577)
at java.io.ObjectInputStream.readEnumDesc(ObjectInputStream.java:1556)
at java.io.ObjectInputStream.readEnum(ObjectInputStream.java:1601)
at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:793)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2003)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1960)
at java.io.ObjectInputStream.readFieldValues(ObjectInputStream.java:1137)
at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:455)
at java.io.ObjectInputStream.readObjectForClass(ObjectInputStream.java:1369)
at java.io.ObjectInputStream.readHierarchy(ObjectInputStream.java:1266)
at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1855)
at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:787)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2003)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1960)
at android.os.Parcel.readSerializable(Parcel.java:2175)
... 18 more

LogCat也说当读取GameServerData.java类的对象时出现问题

GameServerData.java:

public class GameServerData implements Serializable {
    private static final long serialVersionUID = 5912897328563239940L;

    public enum GameState {
        WAITING, PLAYING, FINISHED
    }

    public final int Id;
    public final String White;
    public final String Black;
    public final int WhiteRating;
    public final int BlackRating;
    public final boolean Rated;
    public final int Time;
    public final int Inc;
    public final String StartFen;    
    public String MainLine;

    public long WhiteClock;
    public long BlackClock;

    public PlayerColor Relation;
    public GameState Status;

    public int Countdown;
    public StopEvent StopEvent;
}

PlayerClock,StopEvent是简单枚举的简单枚举,没有复杂的字段。

感谢您的回答!

0 个答案:

没有答案