I've managed to code compile and run a program using these classes before. I think the problem started when I decided to use 'git' in conjunction with 'dropbox' so that I could access 'the same workspace' with both my works windows laptop and my mac that I use at home. I've noticed that the default JRE is changed for each project I work on when using this setup.
I'm not exactly sure how I can remedy this and would appreciate some advice.
It means you compiled with a newer version of Java and are trying to run with an older version, such as compiling with Java 7 but trying to run in a Java 6 environment.
You have 3 options.
1) Upgrade your runtime environment to match your development environment. (Make your JRE match your JDK.)
2) Downgrade your dev environment to match your runtime. (Make your JDK match your JRE.)
3) Use the -source and -target target args when compiling. So, for instance, if your runtime is 1.6, and your JDK is 7, you'd do something like javac -source 1.6 -target 1.6 *.java (Double check the docs for details, I might not have it quite right.)
Thanks for the prompt reply. I had a look in the properties for the specific project and enforced the JDK compiler compliance level to be 6.0. My code now compiles on one of my machines, but I'll keep in mind the info you provided when I have a look at my other machine (work one).
I'll need to be more careful when synchronizing projects. Always a learning curve with java
When you compile a class with one Java version, you cannot use that class in a previous version of Java unless the compiler was targeted at that lower version (using the -target flag). If you get this exact message (with version 51.0), that means that your class is compiled using a Java 7 compiler without targeting Java 6 or below. That in turn means that you can only use the class with a Java 7 JVM.
It's actually pretty easy to upgrade your JVM.
1) Download the latest Java 7 JRE.
2) Install the downloaded JRE.
3) Go to Add/Remove programs and remove the old JRE version (optional step).
That's it. The Java 7 JRE will be used as the default even if you don't uninstall the Java 6 JRE. I have both Java 6u32 and Java 7u4 installed on my machine.
You can do the same for your JDK, although it's not necessary unless you want to use Java 7 specific methods, classes or syntax in your new classes.
Joined: May 18, 2012
But remains a question.
I used cloudsim3 library in my project and i want to run example 1 of it.
In read me file of cloudsim 3.0 is written : Java 6 or newer is required.
Why it doesn,t work with it?
I download and install Jre 7 ,
But the error does not resolved!
Can anyone explain more about option number 3 in above post written by jeff?
For who taht is beginner in java and javac swithes.
Joined: May 18, 2012
Typing it in cmd:
javac -source 7 -target 1.6
javac: invalid source release : 7