无法修复:java.io.NotSerializableException 在 java.io.ObjectOutputStream.writeObject 0(未知来源)

Cant fix: java.io.NotSerializableException at java.io.ObjectOutputStream.writeObject0(Unknown Source)

我对 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。 该方法在调用时获取应保存的文件,我确定它存在,所以不会有问题。 有人知道我可以解决这个问题吗?谢谢:)

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