This site requires JavaScript, please enable it in your browser!
Greenfoot back
Kartoffelbrot
Kartoffelbrot wrote ...

2013/10/13

Compliling error

Kartoffelbrot Kartoffelbrot

2013/10/13

#
Hello everyone, this is my code (Ok, it isn't my code, I got it from a friend):
public static Object deserialize(String filename) {
        Object objekt = null;
        try {
            FileInputStream file = new FileInputStream(filename);
            ObjectInputStream o = new ObjectInputStream(file);
            objekt = o.readObject();
            o.close();
        } 
        catch (IOException | ClassNotFoundException e) { System.out.println(e); }
        return objekt;
    }
If I want to compile I get the error: multi-catch Statement is not supported in-source 1.6 (use-source 7 or higher to enable multi-catch Statement) in the catch line. I reinstalled Java and Greenfoot I have still this error. What's wrong?
erdelf erdelf

2013/10/13

#
greenfoot cant use java 7, and in java 6 u cant catch mutiple errors in one catch line. rewrite the catch line to this, and i think it should work
        catch (IOException e) { System.out.println(e); } 
        catch(ClassNotFoundException e) { System.out.println(e); }
Kartoffelbrot Kartoffelbrot

2013/10/13

#
Oh, that's why it works in BlueJ and not in Greenfoot. It works now, thank you!
You need to login to post a reply.