为了账号安全,请及时绑定邮箱和手机立即绑定

反序列化抛出 java.lang.ClassCastException

反序列化抛出 java.lang.ClassCastException

摇曳的蔷薇 2023-10-13 15:23:01
我在 Android 设备上保存了一个序列化的类。将其传输到 win 10 PC 并通过以下方式加载文件:fis = new FileInputStream(result.get(i));ois = new ObjectInputStream(fis);Object obj = ois.readObject();Android 和 win 10 上的类是:public class ImgLogFile implements Serializable{        byte[] frame;        byte[] result;        String config;    public String getConfig(){            return config;        }    public byte[] getFrame() {        return frame;    }    public byte[] getResult() {        return result;    }} 当我尝试将加载的对象转换为它的类时,我得到:Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: class [Lde.mtt.smartiePlatform.ImgLogFile; cannot be cast to class de.mtt.smartiePlatform.ImgLogFile ([Lde.mtt.smartiePlatform.ImgLogFile; and de.mtt.smartiePlatform.ImgLogFile are in unnamed module of loader 'app')我注意到一条路径前面有一个“L”,但不知道它是什么意思。我怎样才能解决这个问题 ?
查看完整描述

1 回答

?
HUWWW

TA贡献1874条经验 获得超12个赞

[...] 类 [Lde.[...] 无法转换为类 de.[...]

表示[一个数组。[L是后面的引用类型的数组。

因此,您已经序列化了一个数组,并尝试将反序列化的对象转换为非数组的类型。

(此外,使用 Java 序列化并不是一个好主意。)


查看完整回答
反对 回复 2023-10-13
  • 1 回答
  • 0 关注
  • 68 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信