代码之家  ›  专栏  ›  技术社区  ›  qBASHp

无法修复:java.io。java.io.ObjectOutputStream处的NotSerializableException。WriteObject 0(未知源)

  •  0
  • qBASHp  · 技术社区  · 7 年前

    我对 java.io.NotSerializableException at java.io.ObjectOutputStream.writeObject0(Unknown Source) 。这是代码的重要部分。

    public class PlayerConfigAccess implements Serializable{
    
        private static final long serialVersionUID = 1L;
    
        //some load and create methods
    
        public static void saveFile (File file, Player player)
        {
        Object object = (Object) PlayerConfigContent.getContent(player);
    
        if(!existFile(file))
        {
            createFile(file);
        }
    
        try{
    
            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
            oos.writeObject(object);
            oos.flush();
            oos.close();
            PlayerConfigContent.remove(player);
        }catch(Exception e){
            e.printStackTrace();
    
        }
    
    }
    

    我要保存的对象是 PlayerConfig 我转换回的自定义对象 Object 该方法获取调用时应保存的文件,我确保它存在,因此不会出现问题。 有人知道谁可以解决这个问题吗。谢谢:)

    1 回复  |  直到 7 年前
        1
  •  1
  •   Jamal H    7 年前

    您实际编写的对象需要是可序列化的,而不是实际包含编写代码的类。对象类型是什么 PlayerConfigContent.getContent