开发者

My class java has suddenly become un-serializable

One of my classes has suddenly started to complain about it being non-serializable. I have changed some things in it but can't see anything in its definitions that could be causing it.

I get the notserializableexception on that class.

These are all the definitions at the start of the class and I can't see anything there that would cause problems.

private static final long serialVersionUID = 1L;
private ArrayList <Card> cards;
private ArrayList <Card> selectedCards;
private HashSet <Card> knownCards;
private ArrayList <Card> aceHighs;
private int numberOfKnownCards = 0;
private int valueOfKnownCards = 0;

public static final int sortHand = 1;
public static final int sortSelectedCards = 2;
protected int[] cardsPerSuit = {0,0,0,0}; 
private int numberOfDifferentSuits = 0;
private int[] cardsPerRank = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
private int numberOfDifferentRanks = 0;



private int whereToTakeFrom;
private int whichDiscardToTake;

private int cardCount = 0;
private int selectedCount = 0;
public  int handValue = 0;
private Deck deck;

Stack:

05-08 23:46:42.235: DEBUG/AndroidRuntime(1625): Shutting down VM
05-08 23:46:42.235: WARN/dalvikvm(1625): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
05-08 23:46:42.235: ERROR/AndroidRuntime(1625): Uncaught handler: thread main exiting due to uncaught exception
05-08 23:46:42.265: ERROR/AndroidRuntime(1625): java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = il.co.anykey.games.yaniv.lite.AutomatedPlayer)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at android.os.Parcel.writeSerializable(Parcel.java:1131)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at android.os.Parcel.writeValue(Parcel.java:1085)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at android.os.Parcel.writeMapInternal(Parcel.java:469)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at android.os.Bundle.writeToParcel(Bundle.java:1445)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at android.os.Parcel.writeBundle(Parcel.java:483)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at android.app.ActivityManagerProxy.activityPaused(ActivityManagerNative.java:1427)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3106)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at android.app.ActivityThread.access$2400(ActivityThread.java:119)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1870)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at android.os.Looper.loop(Looper.java:123)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at android.app.ActivityThread.main(ActivityThread.java:4363)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.lang.reflect.Method.invokeNative(Native Method)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.lang.reflect.Method.invoke(Method.java:521)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at dalvik.system.NativeStart.main(Native Method)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625): Caused by: java.io.NotSerializableException: il.co.anykey.games.yaniv.lite.Hand$1
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1547)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1854)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1696)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1660)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:1153)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:420)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     a开发者_运维技巧t java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1251)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1587)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1854)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1696)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1660)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:1153)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:420)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1251)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1215)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1215)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1587)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1854)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1696)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1660)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:1153)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:420)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1251)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1215)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1587)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1854)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1696)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1660)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:1153)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:420)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1251)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1215)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1587)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1854)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1696)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1660)
05-08 23:46:42.265: ERROR/AndroidRuntime(1625):     at java.io.ObjectOutputStream.write
05-08 23:46:42.316: WARN/ActivityManager(63): Activity pause timeout for HistoryRecord{44d2c128 il.co.anykey.games.yaniv.lite/.YanivGameActivity}
05-08 23:46:42.335: INFO/Process(63): Sending signal. PID: 1625 SIG: 3
05-08 23:46:42.345: INFO/dalvikvm(1625): threadid=7: reacting to signal 3
05-08 23:46:42.396: INFO/dalvikvm(1625): Wrote stack trace to '/data/anr/traces.txt'
05-08 23:46:51.852: WARN/ActivityManager(63): Launch timeout has expired, giving up wake lock!
05-08 23:46:52.395: WARN/ActivityManager(63): Activity idle timeout for HistoryRecord{44d2d728 il.co.anykey.games.yaniv.lite/.YanivSettingsActivity}

These are the two comparators I have that may be are creating the problems:

private Comparator<Card> byRank = new Comparator<Card>()  {

public int compare(Card c1, Card c2) {
   return c2.getCardRank()-c1.getCardRank();
}
};

private Comparator<Card> bySuitAndRank = new Comparator<Card>()  {

public int compare(Card c1, Card c2) {
   return (c1.getCardSuit()-c2.getCardSuit())*100 + c2.getCardRank()-c1.getCardRank();
}
};


According to the stack trace, class il.co.anykey.games.yaniv.lite.Hand$1 (an anonymous class inside class Hand) is not serializable.


Try marking fields that are having problems as transient. Perhaps you can reconstruct them later when you deserialize.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜