IllegalAccessException - Serialization of object that inherits from non-serializable

元气小坏坏 提交于 2019-12-11 09:19:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!