问题
I getting android.widget.ImageView; IllegalAccessException when trying to deserialize my previously serialized object
File presetFile = new File("pathToFile");
FileInputStream fis = new FileInputStream(presetFile);
ObjectInputStream ois = new ObjectInputStream(fis);
Preset preset = (Preset) ois.readObject();
I'm guessing that there is some restriction about ImageView, explanation below:
public class Preset implements Serializable {
private Date dateOfCreation;
private int bpm;
private SoundSwitch[][] switches;
And finally SoundSwitch class header
public class SoundSwitch extends ImageView implements Serializable{
}
Is that because ImageView that I inherit from doesn't implement Serializable? Do I have to give up on deserializing such object?
回答1:
It is because the ImageView you are inheriting from is non-Serializable and doesn't have a public no-args constructor. Evidently it has a protected or package-access or private one.
来源:https://stackoverflow.com/questions/11908353/illegalaccessexception-serialization-of-object-that-inherits-from-non-serializ