Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unsupported major.minor version 51.0

 
Michael Gordon
Greenhorn
Posts: 19
Eclipse IDE Linux Mac
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I am getting an error in Eclipse 'java.lang.UnsupportedClassVersionError: GridBagLayout/GridBagLayoutDemo : Unsupported major.minor version 51.0'

I've coded a short program using 'GridBagLayout' and 'GridBagConstraints' classes and when trying to compile it, I get the aforementioned error.

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.


Many thanks

Michael

 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
Michael Gordon
Greenhorn
Posts: 19
Eclipse IDE Linux Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeff,

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

Thanks,

Michael
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Gordon wrote:I had a look in the properties for the specific project and enforced the JDK compiler compliance level to be 6.0.

That's basically the same as using the third option Jeff provided, only it's the IDE that does it for you.
 
Michael Gordon
Greenhorn
Posts: 19
Eclipse IDE Linux Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the clarification Rob.

I'll try that from the command line just so I can familiarise myself a bit more from that angle. Perhaps learning using an IDE is a bit lazy.


I appreciate the details you guys go into when explaining.

Michael
 
Sara Bony
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote: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.
...

Hi all
I have the same problem .
installing jar and jdk with one program that name is: Jdk6u18
Then how can i upgrade one of them?
Is it the possible the cause of problem is not installing apache ant?

Thanks in advance.
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apache Ant has nothing to do with this.

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.
 
Sara Bony
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
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.
 
Sara Bony
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Typing it in cmd:
javac -source 7 -target 1.6
Result:
javac: invalid source release : 7
??
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Java 6 compiler doesn't know that Java 7 exists. Besides, it wouldn't work. If I try that with my Java 7 compiler I get the following error message:
javac: source release 7 requires target release 1.7

If you want to compile for Java 6, then the source version must be at most 6 as well.
 
Sara Bony
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With installing jdk7, the ptoblem is solved.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic