私のにはandroidアプリケーションで私はライセンスデータを格納するためにファイルを使用します。そして、オブジェクトをシリアル化するを使用します。 デバイスオブジェクトを作成し、オブジェクトのファイル詳細を読み込みます。 デバイスクラスはSerializableを実装しています。Android NotSerializableExceptionはオブジェクトに対して発生します
public class MyDevice implements Serializable {}
しかし、アプリケーションの開始時に、それはをデシリアライズとMYDEVICEオブジェクトに格納します。私のdeserializeObjectメソッドは以下の通りです。
public MyDevice deserializeObject() {
File SerialFile = new File(GeoTrackerPaths.FILE_PATH);
MyDevice AndDeviceIn = new MyDevice();
if (SerialFile.exists()) {
try {
FileInputStream fileIn = new FileInputStream(GeoTrackerPaths.FILE_PATH);
ObjectInputStream objInput = new ObjectInputStream(fileIn);
AndDeviceIn = (MyDevice) objInput.readObject();
objInput.close();
fileIn.close();
} catch (Exception e) {
Log.i("TAG", "Exception during deserialization:" + e.getMessage());
e.printStackTrace();
System.exit(0);
}
}
return AndDeviceIn;
}
私のシリアル化コード
public void serializeObject(Context context, String phoneModel,
String androidVersion, String executiveCode, String Key,
String modelID, String tempKey, int noLogin, String expireDate, String Status) {
try {
MyDevice AndDeviceOut = new MyDevice(context, phoneModel,
androidVersion, new Date(), executiveCode, Key, modelID,
tempKey, noLogin, expireDate, Status);
FileOutputStream fileOut = new FileOutputStream(
GeoTrackerPaths.FILE_PATH);
ObjectOutputStream objOutput = new ObjectOutputStream(fileOut);
objOutput.writeObject(AndDeviceOut);
objOutput.flush();
objOutput.close();
fileOut.close();
} catch (Exception e) {
Log.i("TAG", "Exception during serialization:" + e.getMessage());
e.printStackTrace();
System.exit(0);
}
}
そして、私は以下のようにそれを呼んでいます。
DeviceActivator activate=new DeviceActivator();
activate.serializeObject(Activation.this, phoneModel, androidVersion, txtExe, exeKey, modeilID, tempKey, noLogin, expireDate, Activation_Status);
私が発生した例外以下のアプリを実行していますよ。
java.io.WriteAbortedException: Read an exception;
java.io.NotSerializableException: com.geotracker.entity.MyDevice
どうすればこの問題を解決できますか?
例外はありませんが、新しいMyDeviceオブジェクトを作成してから、ファイルから読み込んだオブジェクトに同じ参照を割り当てる理由は何ですか? –
あなたは "MyDevice AndDeviceIn = new MyDevice();"を意味します。ではない。オブジェクトを格納するためのMyDeviceインスタンスを作成してはいけません.......... –
シリアライズ解除コードの例は間違っていますが、シリアライズ処理を行うコードに問題がある可能性があります。その部分も投稿できますか? – Durandal