小编chi*_*ary的帖子

为什么我得到异常java.io.NotSerializableException?

我得到java.io.NotSerializableException:java.util.ArrayList $ SubList以获取以下代码.

        ObjectInputStream os=new ObjectInputStream(new FileInputStream("AllEMExampleObjects.dat"));
        Set<EntitiyMentionExample> AllEMs=(Set<EntitiyMentionExample>)(os.readObject());
        EntitiyMentionExample[] AllExamples=AllEMs.toArray(new EntitiyMentionExample[0]);

        ObjectOutputStream oo=new ObjectOutputStream(new FileOutputStream("C:\\Users\\15232114\\workspace\\Year2\\FormatedExamples\\TestSerialization.dat"));
        oo.writeObject(AllExamples[0]);
Run Code Online (Sandbox Code Playgroud)

显然,EntitiyMentionExample类是Serializable,这就是它的Set <>已存储在dat文件(AllEMExampleObjects.dat)中的原因.那为什么现在不存储它的单个实例呢?

java serialization

-1
推荐指数
1
解决办法
2015
查看次数

标签 统计

java ×1

serialization ×1