【发布时间】:2020-10-04 04:39:44
【问题描述】:
运行代码后出现以下错误:
关于导致该问题的原因以及如何解决它的任何想法?
这里是Restore():
public void Restore() {
try
{
ObjectInputStream is = new ObjectInputStream(new FileInputStream("dump.out"));
GreenhouseControls greenhouseControls = (GreenhouseControls) is.readObject(); // Line 343
is.close();
Fixable fixable = getFixable(greenhouseControls.getError());
if(fixable != null)
fixable.fix();
else
System.out.println("Nothing to fix");
}
catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
}
如果需要完整代码: https://repl.it/repls/MajesticDarkredCrash#Main.java
example3.txt:
Event=ThermostatNight,time=0
Event=LightOn,time=2000
Event=WaterOff,time=10000
Event=ThermostatDay,time=12000
Event=Bell,time=9000,rings=5
Event=WaterOn,time=6000
Event=LightOff,time=4000
Event=Terminate,time=20000
Event=FansOn,time=7000
Event=WindowMalfunction,time=15000
Event=FansOff,time=8000
我使用 java GreenhouseCOntrols -f emample3.txt 然后 java GreenhouseControls -d dump.out 来运行程序。
【问题讨论】:
-
欢迎来到 Stack Overflow。请通过tour 了解 Stack Overflow 的工作原理,并阅读How to Ask 了解如何提高问题的质量。然后edit你的问题包含你拥有的源代码(特别是
GreenhouseControls类)作为minimal reproducible example,可以被其他人编译和测试。 -
您链接到的代码显然不是您正在运行的代码,因为您的代码中没有任何地方可以将输出序列化为文件。此外,您的评论
line 343出现在第 325 行。 -
@LukeWoodward 它应该是相同的代码,当我通过 repli 时,我刚刚删除了一些 cmets。但是你说有什么东西可以序列化到一个文件中是什么意思?
-
当我说没有任何东西可以将输出序列化到文件时,我的意思是没有任何东西可以生成
dump.out文件。您正在加载的dump.out文件来自哪里?
标签: java serializable