我的代码运行后出现以下错误。
知道是什么原因造成的吗? 如何解决?
以下是 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.itreplsMajesticDarkredCrash#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
来运行程序。
无论你在行中试图将什么对象类型化为GreenhouseControls
GreenhouseControls greenhouseControls = (GreenhouseControls) is.readObject();
是不工作的。因此,你似乎在读取一个不符合GreenhouseControls的对象。
你能不能也提供文件内容?