0
votes

I have the JRE 1.6 and 1.7 installed (as well as the JDK) in c:/program files/java/

I first had 1.7 installed then installed 1.6 as well. I am using Eclipse as my IDE -please note I am new to Java.

When I want to switch to 1.6 I go to "Run configurations" (in Eclipse) and select alternative JREs, pick 1.6 and click apply. But when I try to run a simple HelloWorld program I get this alert:

Could not find the main class:HelloW. Program will exit.

And in the console I get these errors:

java.lang.UnsupportedClassVersionError: HelloW : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)

If I switch back to JRE 1.7 everything works again. How can I properly switch to 1.6 and get everything working?

2
You need to recompile everything, because the 1.6 VM cannot work with the classfiles from 1.7. Just clean your projects.Ingo

2 Answers

3
votes

Your HelloW class is compiled for 1.7 so it won't run on 1.6. You have to recompile the code using an older version.

In eclipse you can right click on your project then go to "Properties", then click on "Java Compiler". check enable project specific settings, and change the JDK Compliance like this:

enter image description here

1
votes

The error which is occurring here is that you have compiled the file in java 1.7 and trying to run it in java 1.7.

I would suggest that after u change JRE to 1.6 re-compile the code file i.e. rebuild the project and then run the project.

As per JRE policy, if we have compiled project on new version and then try to run it on old version it will not run and throw major/minor version error. Therefore please recompile it on JRE 1.6 and then run.