相关疑难解决方法(0)

Java:在重构=>"class not found"异常后加载保存在硬盘上的对象:/

我正在使用这种简单的方法在java中开发一个常规将对象保存到硬盘上的应用程序:

public void save(String filename)
{
    try
    {
        FileOutputStream fos = new FileOutputStream(filename);
        GZIPOutputStream gzos = new GZIPOutputStream(fos);
        ObjectOutputStream out = new ObjectOutputStream(gzos);
        out.writeObject(this);
        out.flush();
        out.close();
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }

}
Run Code Online (Sandbox Code Playgroud)

该对象是sebbot.learning.DirectPolicySearch类的实例.

问题是,经过一些重构后,学习包被重命名为"ballcapture".现在,当我尝试加载保存的文件时,我得到以下异常:

java.lang.ClassNotFoundException:sebbot.learning.DirectPolicySearch

我用来加载文件的方法是:

public static synchronized DirectPolicySearch load(String filename)
{
    DirectPolicySearch dps = null;
    try
    {
        FileInputStream fis = new FileInputStream(filename);
        GZIPInputStream gzis = new GZIPInputStream(fis);
        ObjectInputStream in = new ObjectInputStream(gzis);
        dps = (DirectPolicySearch) in.readObject();
        in.close();
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }

    System.out.println(dps);

    return …
Run Code Online (Sandbox Code Playgroud)

java load exception object save

5
推荐指数
1
解决办法
1816
查看次数

标签 统计

exception ×1

java ×1

load ×1

object ×1

save ×1