Exception in thread “main“ java.io.NotSerializableException:

这个问题我遇到是在使用对象序列化流时发生的

他就是在告诉我们 类需要实现一个来自java io表下的Serializable接口

例如 我这里 要将customException的内容写入文件当中 我们就在customException中编写

import java.io.Serializable;

public class customException implements Serializable {
    
    
    private String name;
    private int age;

    public customException(String name,int age){
    
    
        this.name = name;
        this.age = age;
    }

    public void setName(String name){
    
    
        this.name = name;
    }
    public String getName(){
    
    
        return this.name;
    }
    public void setAge(int age){
    
    
        this.age = age;
    }
    public int getAge(){
    
    
        return this.age;
    }
}

import java.io.Serializable; 引入Serializable

类名 implements Serializable 实现接口即可

猜你喜欢

转载自blog.csdn.net/weixin_45966674/article/details/127352613