gpt4 book ai didi

java - 反序列化抛出 java.lang.ClassCastException

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:05:14 24 4
gpt4 key购买 nike

我在 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”,但不知道它是什么意思。我怎样才能解决这个问题 ?

最佳答案

[...] class [Lde.[...] cannot be cast to class de.[...]

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

所以你已经序列化了一个数组,并试图将反序列化的对象转换为一个不是数组的类型。

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

关于java - 反序列化抛出 java.lang.ClassCastException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58323843/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com