我試圖序列配對如下:類實現Serializable接口不能的readObject
private void writeObject(java.io.ObjectOutputStream out) throws IOException {
if (mPair != null) {
String first = mPair.first;
String second = mPair.second;
mPair = null;
try {
out.writeChars(first);
out.writeChars("\n");
out.writeChars(second);
} catch (Exception e) {
}
}
}
private void readObject(java.io.ObjectInputStream in) throws IOException,
ClassNotFoundException {
try {
String first = in.readLine();
String second = in.readLine();
mPair = new Pair<String, String>(first, second);
} catch (EOFException e) {
mPair = new Pair<String, String>("", "");
}
}
我調試的是writeObject
被稱爲正常我有我的自定義類的對象,當我的應用程序去屏幕外的3,但是當我來到回到應用程序readObject
永遠不會被調用。
那是ObjectInputStream已經連接FileOutputStream像這裏嗎? http://www.tutorialspoint.com/java/java_serialization.htm請注意,我不知道整個過程如何在基於android的設備上工作。你是否調用這些方法,或者你是否展示了android SDK? (如果是這樣的:你確定它是這樣嗎?) – JBA
我已經以相同的方式爲Rect實現了序列化,並且它可以正常工作。 – Niko
對不起,我沒有幫助,然後:( – JBA