This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Unsupported major.minor version 51.0 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Unsupported major.minor version 51.0" Watch "Unsupported major.minor version 51.0" New topic
Author

Unsupported major.minor version 51.0

Michael Gordon
Greenhorn

Joined: Nov 01, 2011
Posts: 19

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

Joined: Jan 03, 2004
Posts: 6109
    
    6

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

Joined: Nov 01, 2011
Posts: 19

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

Joined: Oct 27, 2005
Posts: 19654
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Michael Gordon
Greenhorn

Joined: Nov 01, 2011
Posts: 19

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

Joined: May 18, 2012
Posts: 18
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

Joined: Oct 27, 2005
Posts: 19654
    
  18

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

Joined: May 18, 2012
Posts: 18
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

Joined: May 18, 2012
Posts: 18
Typing it in cmd:
javac -source 7 -target 1.6
Result:
javac: invalid source release : 7
??
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

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

Joined: May 18, 2012
Posts: 18
With installing jdk7, the ptoblem is solved.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Unsupported major.minor version 51.0
 
Similar Threads
tomcat 7 encounters LifecycleException caused by java.lang.UnsupportedClassVersionError
Unsupported major.minor version 50.0
Question concerning java versions between java and javac
Servlet running on Local host but throwing Exception on public server
and onto graphics