3

I have an old Java 6 Project in Eclipse. To use functionality of Java 7 I would like to switch to Java 7. I am not able to do it :

Goal->No compilation errors in my Java Code . See red underlinded the compilation error when using ZipFile with 2 parameters used for Java 7. The Constructor of ZipFile in Java 6 has one argument. In Java 7 there are 2 arguments: enter image description here

My Environment in my project: enter image description here

Compilation Error is:

Exception in thread "main" java.lang.Error: Unresolved compilation problems: The constructor ZipFile(String, Charset) is undefined The constructor ZipFile(String, Charset) is undefined at ZipCompare.compare(ZipCompare.java:103) at ZipCompare.main(ZipCompare.java:77) 

enter image description here

enter image description here

enter image description here

When I create a new Project from scratch, there are no compilation errors. I compared all settings from my old project and the new one and did not find any differences so far ?

Any help ?

14
  • 4
    Thanks for all the screens, and now tell us what is your compilation error. BTW Java 7 ZipFile has all the constructors of Java 6, plus additional ones. They take from one to three arguments. Commented Jan 19, 2014 at 10:06
  • In the first screen you can see the compilation error. Its red underlined and I also mentoined it in the text. Its because I use 2 arguments. Off course when using 1 argument there is no compilation error, but I want to set the Characterset. Commented Jan 19, 2014 at 10:14
  • 3
    Java goes to obnoxious lengths to make old code workable in new compilers; to my knowledge, the only breaking change was the introduction of enum as a keyword. As Marko mentioned, the Java 7 API still has all those constructors, so something else is broken. The problem appears to be that you installed just a JRE and not a JDK. Commented Jan 19, 2014 at 10:40
  • 1
    What is the exact message of the error? Btw have you tried to restart Eclipse. It might seem stupid but it sometimes works. Eclipse has some bugs too. Commented Jan 19, 2014 at 11:17
  • 3
    "In the first screen you can see the compilation error" - no, we can't. We can see the line causing the error, but not the actual error message. Also, please never post screenshots of code, code should always be posted as text - and when you post it as text, make sure that your code is complete and self-contained. In case of the screenshot you posted, we can't diagnose the error as we don't even see the declarations of all your variables. Commented Jan 19, 2014 at 11:24

2 Answers 2

1

Here are the exact steps in case anyone in the future needs them:

  1. In the Package Explorer window, right-click your project and select "Properties" from the context menu, or go to File > Properties.

  2. In the Properties dialog window, select "Java Build Path" from the left sidebar menu, then click the Libraries tab on the right-hand side.

  3. Select your 'JRE System Library' and click the "Edit..." button. Assuming you have the latest JRE installed, you should be able to change the "Execution environment" there.

  4. If not, go to "Alternate JRE:" and click the "Installed JREs..." button.

  5. Assuming you don't see the one you want listed, click "Add...", ensure "Standard VM" is selected, click "Next", click "Directory" and navigate to your new JRE root folder (i.e., "C:\Program Files\Java\jre1.8.0_20").

  6. Once you click "Finish" and then "OK", you should be able to switch back to "Execution environment" and select the JRE you desire.

  7. Click "Finish" and then select "Java Compiler" from the left sidebar menu. Double check that under JDK Compliance you have "Use compliance from execution environment...." checked.

Now your project should compile and run under the new JDK/JRE.

Sign up to request clarification or add additional context in comments.

Comments

0

My messy solution. I don't know if there are sideeffects. So far no:

  1. Rename the old project to XXXXX_OLD
  2. Create new Project XXXXX with initial JAVA7 Environment
  3. Close Eclipse
  4. Copy Content of Folder XXXXX_OLD to XXXXX
  5. Start Eclipse. No Compilation Error anymore for my Constructor ZipFile(1,2)

I would really like to know the right way. I only gave this solution for probably help other peoples with the same issue. Use this Method on your own RISK! Its messy.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.