[ACCEPTED]-java.lang.UnsupportedClassVersionError: Bad version number in .class file-unsupported-class-version

Accepted answer
Score: 14

You get this error when you try to run a 10 class that was compiled for a Java version 9 newer than what you have; for example, if 8 you try to use a class that was compiled 7 for Java 6 or newer on a Java 5 JVM.

It doesn't 6 necessarily have to be your own class; you 5 might be using some library that was built 4 for Java 6 or newer.

Are you using specific 3 libraries (JAR files)? Check if these are 2 compatible with Java 5 or not. Or upgrade 1 your Java version to Java 6.

Score: 2

My guess is that you are using 3rd party 4 libraries built with Java 1.6.

By the way 3 is there any reason you are using Java 1.5? Java 2 1.6 is out for long and Java 1.5 will no 1 longer be supported real soon (if not already).

Score: 0

You have a class compiled for a newer Java 4 than the one you are using.

The stack trace 3 should show the name of the troublesome 2 class. Perhaps it is a library you are 1 using?

Score: 0

You may find that the version of java that 10 is being used is not the copy that the code 9 was expecting.

For example, if your $PATH 8 (this example is on Unix) is set to /usr/bin:(other 7 directories) you would get /usr/bin/java 6 when you run java:

    $ java -version
    java version "1.5.0_18"
    Java(TM) Platform, Standard Edition for Business (build 1.5.0_18-b02)
    Java HotSpot(TM) Server VM (build 1.5.0_18-b02, mixed mode)
    $ which java

...but your program needs 5 something like this to work:

    $ /usr/local/java/jdk1.6/bin/java -version
    java version "1.6.0_14"
    Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
    Java HotSpot(TM) Server VM (build 14.0-b16, mixed mode)

so the fix would 4 be to add the directory where your correct 3 version of java lives to the start of your 2 path before calling java, or call the good 1 version java by its absolute path.

Score: 0

If upgrading your JRE is not an option, you 5 can compile your code with lower java version.

From 4 eclipise:

Project properties > Java compiler 3 > Compiler compliance level> [Set to whatever 2 JRE version you have]

See below screen for 1 setting JRE 1.5 compatibility

Score: 0

If you observe carefully, the project modules 20 are not in the package icon... In IntelliJ 19 or any IDE, it should be the same... Due 18 how .jar or any bundle works.

Follow this 17 simple steps:

right click on project's root 16 folder, then select 'mark as directory' option 15 and select root folder option ...

PS: (Optional 14 part) Excuse me for not posting any screen 13 shots... I just felt it's lil more straight 12 forward.

The error is trying to say that 11 the modules are not grouped, that's why 10 the compiler says, not in root folder... Which 9 is true, because your modules are scattered 8 all over the IDE... For some reason.

And 7 as for the wording in the error... It means 6 that the version is not included as part 5 of the packages to be compiled, remember 4 standard of programming... purpose of packages 3 ... And When adding stuff to a jar... They 2 must be grouped before. Into a folder as 1 the root for jvm.

Thank you once more.

More Related questions