-1

I'm getting the following error after running my code:

enter image description here

Any ideas on what causing that and how to fix it?

Here is 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();
        }
    }

Full code if needed: 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

i'm using java GreenhouseCOntrols -f emample3.txt then java GreenhouseControls -d dump.out to run the program.

dxbh0517
  • 41
  • 7
  • Welcome to Stack Overflow. Please take the [tour] to learn how Stack Overflow works and read [ask] on how to improve the quality of your question. Then [edit] your question to include the source code you have (specially the `GreenhouseControls` class) as a [mcve], which can be compiled and tested by others. – Progman Jun 14 '20 at 19:18
  • You might want to look at https://stackoverflow.com/questions/13895867/java-io-notserializableexception – Progman Jun 14 '20 at 19:19
  • The code you linked to evidently isn't the code you are running because nowhere in your code is there anything that serializes the output to a file. Also, your comment `line 343` appears on line 325. – Luke Woodward Jun 14 '20 at 19:47
  • @LukeWoodward it should be the same code I just removed some comments when I passed in replit. but what do you mean by there's anything that serializes to a file? – dxbh0517 Jun 14 '20 at 19:54
  • When I say there isn't anything that serializes output to a file, I mean that there's nothing that generates a `dump.out` file. Where does the `dump.out` file you are loading in come from? – Luke Woodward Jun 15 '20 at 20:46

1 Answers1

0

Whatever object you are trying to typecast to GreenhouseControls in the line

GreenhouseControls greenhouseControls = (GreenhouseControls) is.readObject();

is not working. So it seems you are reading a object that doesnot match GreenhouseControls

Can you also provide the File contents?

  • I don't think that's the problem. The error is thrown when it's *writing* the object, not reading it. Also, casting shouldn't throw a NotSerializableException – user Jun 14 '20 at 18:58
  • 1
    I added examples3.txt to the question and the run commands used, these should show you the full output along with dump.out I can't seem to read it on my end to post here sorry – dxbh0517 Jun 14 '20 at 19:13