-3

I am writing serialization code for eclipse I am trying to use FileOutputStream with try-with-resource but I am getting a error message : "Resource specification not allowed here for source level below 1.7" And as fix Eclipse is showing the message "Change project compliance and JRE to 1.7". This is a new error for me, please help.

public static void main(String[] args) {
    Employee employeeOut = null;

    try(FileOutputStream fos = new FileOutputStream("Employee.ser");
            ObjectOutputStream oos = new ObjectOutputStream(fos) ){

    }
}

I want to compile this class.

Avdhut
  • 120
  • 3
  • 13

2 Answers2

4

To solve this problem in Eclipse, right click on the project, then properties > Java Build Path > Libraries > Add Library > JRE System Library and then follow the menu selection.

You can select the JDK installation location.

PythonLearner
  • 1,174
  • 2
  • 16
3

Your project setup is wrong. To fix that, right click your project, then select Properties.
Select "Build Path", and the tab "Libraries". Build Path
Select JRE System Library, and click "Edit...". JRE System Library Select "Execution environment" "JavaSE-1.8", then "Finish". Now select "Java Compiler" on the left. Java Compiler Make sure "Use compilance from execution environment 'JavaSE-1.8' on the 'Java Build Path'" is checked.

This should fix your problem.

Johannes Kuhn
  • 12,878
  • 3
  • 41
  • 66