Unsupported major.minor version 51.0
The other day I was trying to compile and run some swing example code using the command line and when I tried to execute I got the following error:
Exception in thread “main” java.lang.UnsupportedClassVersionError: Main : Unsupported major.minor version 51.0
I found on the Internet that version 51.0 corresponds to java 1.7 and then I realised that I have jdk 1.7 installed while my jre is 1.6.
I usually don’t care about this compatibilty issues because NetBeans takes care of this.
So the solution is to tell javac to compile it for 1.6:
javac -source 1.6 -target 1.6 MyClass.java
And then it worked like a charm.
This kind of error is due to version differences between the binaries and the virtual machine and can be solved like I wrote above. Having said that remember that if you have some incompatible source code between versions javac compiler will complain.