アクティビティが onDestroy() を呼び出すときにシリアライズされたオブジェクトを保存しようとしていますが、ObjectOutputStream を使用してオブジェクトを書き込もうとすると、java.io.NotSerializableExeption がスローされます。
手伝ってくれませんか。ありがとう
アクティビティが onDestroy() を呼び出すときにシリアライズされたオブジェクトを保存しようとしていますが、ObjectOutputStream を使用してオブジェクトを書き込もうとすると、java.io.NotSerializableExeption がスローされます。
手伝ってくれませんか。ありがとう
私は同じ問題に遭遇し、シリアライゼーションを支援するためにこのクラスを作成しました:
public class SerializableRect implements Serializable {
private static final long serialVersionUID = 1L;
private Rect mRect;
public SerializableRect(Rect rect) {
mRect = rect;
}
public Rect getRect() {
return mRect;
}
private void writeObject(java.io.ObjectOutputStream out) throws IOException {
int left = mRect.left;
int top = mRect.top;
int right = mRect.right;
int bottom = mRect.bottom;
out.writeInt(left);
out.writeInt(top);
out.writeInt(right);
out.writeInt(bottom);
}
private void readObject(java.io.ObjectInputStream in) throws IOException,
ClassNotFoundException {
int left = in.readInt();
int top = in.readInt();
int right = in.readInt();
int bottom = in.readInt();
mRect = new Rect(left, top, right, bottom);
}
}
クラスがインターフェイスを実装していることを確認する必要がありjava.io.Serializable
ます。また、代わりにバンドルを使用し、データを に保存することも検討してくださいonSaveInstanceState
。データ ストレージの詳細については、この開発者ガイドのトピックを参照してください。