反序列化抛出 java.lang.ClassCastException

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


摇曳的蔷薇
浏览 70回答 1
1回答

HUWWW

[...] 类 [Lde.[...] 无法转换为类 de.[...]表示[一个数组。[L是后面的引用类型的数组。因此,您已经序列化了一个数组,并尝试将反序列化的对象转换为非数组的类型。(此外,使用 Java 序列化并不是一个好主意。)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java