Guide on Programming, Internet and Technology

DigiZol
| Contact

java.lang.UnsupportedClassVersionError: Bad version number in .class file

java.lang.UnsupportedClassVersionError: Bad version number in .class file
[at java.lang.ClassLoader.defineClass1(Native Method)]
is an error that you may face in running a compiled java class file.


So as you can see from the stack trace, a class has not been loaded. But which class? The problem is this error message does not show the name of the failed .class, isn't it?

No, it is not. This error is caused when you compile a .java file with one version of JDK and running the .class file with a different version of JVM.

Confused? You may say; same version is not required to compile and run.

Yes, that is true. But you can not run .class files that are compiled with a newer version than the JVM.

Say;
javac (compile) - version: X
java (run) - version: Y
If X is newer than Y; then you may face this issue at runtime.

Now you know how to solve this issue, isn't it?

Labels: ,

Translate into your language
Reader Comments
Comments Count: 14
Write your own opinion
Share with others
E-mail
Search More Articles
  1. I tried 2 run some class files on java 1.5 I received from a friend and faced this error. Thanks for pointing the solution.
  2. It's crystal clear explanation. bunch of thanks Kamal.
  3. Thanks Kamal! Your post helped me.
  4. Dear Friend im facing the same problem but as u explaned i dont know how to use these commands plz help
  5. Hello friend,

    Please check the versions of javac and java on your computer and post them here, then we'll create the required commands.
  6. Wow cool
    I can fix my problem by you posted
  7. how is it that i remember being able to issue a "javac -version" before that worked, but now i can't figure out how to check my compiler version?

    java -version (always works)
    javac -version (now never works)

    darksalmon
  8. java version "1.6.0_12"
    Java(TM) SE Runtime Environment (build 1.6.0_12-b04)
    Java HotSpot(TM) Client VM (build 11.2-b01, mixed mode, sharing)

    javac 1.6.0_12

    I got the versions as above, but still getting this error. I have tried compiling it with or without -cp option, but it is still failing to run. I am able to get this to work from another workstation. Can you please help?
  9. im facing the same problem but when i installed 1.5 it didnt showed any error but at run time it is showing the error
    and java -version is showing 1.3.1 version
  10. i installed latest 1.6 jvm and jre. javac -version is showing 1.6 but java -version is still showing 1.3 may be older version is not unistalled properly. help me
  11. Hi Satyam,

    Best thing to resolve this would be, first remove all jre/jdk installations. (Better not to install two different versions on one machine.)

    Then check for versions of both. That way you will be able to resolve this issue.
  12. Anonymous Anonymous (April 06, 2009 10:17 AM)  
    I am getting this error for groovy 1.6.0.

    java.lang.UnsupportedClassVersionError: org/codehaus/groovy/tools/GroovyStarter (Unsupported major.minor version 49.0)

    and my java -version is java version "1.6.0_11"

    Any thoughts?
  13. Anonymous Anonymous (April 17, 2009 6:11 PM)  
    I think 49.0 => Java 1.5 ... are you sure all were recompiled?
    Doesn't it identify the bad class file?
  14. I got the same exception and I solved it
    java.lang.UnsupportedClassVersionError: Bad version number in .class file
    [at java.lang.ClassLoader.defineClass1(Native Method)]

    I was using JDK 1.5
    I was trying to connect from eclipse using "postgresql-8.3-603.jdbc4.jar"
    this driver. This jdbc driver.

    After the error message i went to http://jdbc.postgresql.org/download.html
    and found a compatibility list like this
    * JDK 1.1 - JDBC 1. Note that with the 8.0 release JDBC 1 support has been removed, so look to update your JDK when you update your server.
    * JDK 1.2, 1.3 - JDBC 2.
    * JDK 1.3 + J2EE - JDBC 2 EE. This contains additional support for javax.sql classes.
    * JDK 1.4, 1.5 - JDBC 3. This contains support for SSL and javax.sql, but does not require J2EE as it has been added to the J2SE release.
    * JDK 1.6 - JDBC4. Support for JDBC4 methods is limited. The driver builds, but the majority of new methods are stubbed out.

    So i used "postgresql-8.3-604.jdbc3.jar" instead of jdbc4.

    And then my connection was found by eclipse ran without any problem

Post a Comment

We appreciate your opinions, suggestions and criticism.

ABOUT AUTHOR
Kamal Mettananada is a Software Architect, Java Explorer and Blogger. Digizol consists of computer related articles, tutorials, tips and other information.
ARCHIVES
Select Month:

Free counter and web stats

FEED SUBSCRIPTION
Subscribe to our feed using your online news reader, approximately 1-2 articles per week.
ABOUT US
^top^