我写了一个名为Node的类
而且我需要它是可序列化的,这样它将作为 Intent 的额外内容。
我收到这个错误,我很困惑。
Parcelable encountered IOException writing serializable object (name = com.rachel.MainActivity$Node)
这是代码:
class LineSeconds implements Serializable {
String line;
int seconds;
public LineSeconds(String line, int seconds) {
this.line = line;
this.seconds = seconds;
}
}
class Item implements Serializable {
ArrayList<LineSeconds> list;
String option1;
String option2;
int special;
public Item(ArrayList<LineSeconds> list, String option1, String option2, int special) {
this.list = list;
this.option1 = option1;
this.option2 = option2;
this.special = special;
}
}
class Node implements Serializable {
Item key;
Node left, right;
int numWritten = 0;
public Node(Item key, Node left, Node right) {
this.key = key;
this.left = left;
this.right = right;
}
}
这是我使用序列化的时候:
其中 toRewind 是一个节点。 numGoBackTo 是一个 int。
finish();
Intent restart = new Intent(cont, MainActivity.class);
restart.putExtra("toRewind", toRewind);
restart.putExtra("numGoBackTo", numGoBackTo);
startActivity(restart);
最佳答案
我认为 cont 是你的 Contex 变量,所以你忘记在末尾添加 cont
cont.startActivity(重新启动)
关于java - Java 中的序列化问题 (Android Studio),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56594161/