我在 Android 設(shè)備上保存了一個序列化的類。將其傳輸?shù)?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; }} 當(dāng)我嘗試將加載的對象轉(zhuǎn)換為它的類時,我得到: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貢獻(xiàn)1874條經(jīng)驗(yàn) 獲得超12個贊
[...] 類 [Lde.[...] 無法轉(zhuǎn)換為類 de.[...]
表示[
一個數(shù)組。[L
是后面的引用類型的數(shù)組。
因此,您已經(jīng)序列化了一個數(shù)組,并嘗試將反序列化的對象轉(zhuǎn)換為非數(shù)組的類型。
(此外,使用 Java 序列化并不是一個好主意。)
添加回答
舉報(bào)
0/150
提交
取消