In my case, this error appeared when I attempted to load a class from a batch file in the Windows command prompt.
“Caused by: java.lang.UnsupportedClassVersionError: (*myclassname*) bad major version at offset=6”
This error indicates that your projects were compiled with a higher level Java compiler than the runtime can support.
Firstly, confirm what version of Java is installed on your machine. In Windows, open a command prompt window and enter the following command:
The output will look something like:
java version "1.5.0_22"
Java(TM) SE Runtime Environment (build 1.5.0_22-b03)
Java HotSpot(TM) Client VM (build 1.5.0_22-b03, mixed mode, sharing)
This message confirmed that my runtime environment was Java 5 – but error above was stating the classes had been compiled in Java 6. The next step is to check what version of Java is being used to compile your project. In my case, I was using Eclipse.
Go to Window > Preferences > Java > Installed JREs and make sure your 5.0 runtime shows up in the list and is checked. If nothing suitable appears in the list of options, then you need to download the correct Java version from the Sun website.
Finally, go to Window->Preferences->Java->Compiler and ensure that your Compiler compliance level is set to 1.5.