【问题标题】:IllegalAccessException - Serialization of object that inherits from non-serializableIllegalAccessException - 从不可序列化继承的对象的序列化
【发布时间】:2012-08-08 03:36:48
【问题描述】:

我得到了 android.widget.ImageView;尝试反序列化我之前序列化的对象时出现 IllegalAccessException

        File presetFile = new File("pathToFile");

        FileInputStream fis = new FileInputStream(presetFile);      
        ObjectInputStream ois = new ObjectInputStream(fis);
        Preset preset = (Preset) ois.readObject();

我猜ImageView有一些限制,解释如下:

public class Preset implements Serializable {

    private Date dateOfCreation;
    private int bpm;
    private SoundSwitch[][] switches;

最后是 SoundSwitch 类头

public class SoundSwitch extends ImageView implements Serializable{
}

那是因为我继承的 ImageView 没有实现 Serializable 吗?我必须放弃反序列化这样的对象吗?

【问题讨论】:

    标签: android serialization deserialization


    【解决方案1】:

    这是因为您继承自的ImageView 是不可序列化的并且 没有公共的无参数构造函数。显然它有一个受保护的或包访问或私有的。

    【讨论】:

    • @Chris No. 从其他东西继承。
    猜你喜欢
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多