Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Reg : java.lang.UnsupportedClassVersionError

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I checked out a new project from CVS and was able to build it without any compilation errors. When I try to run the application is throws an exception.

Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class []: Constructor threw exception; nested exception is java.lang.UnsupportedClassVersionError: Bad version number in .class file

I checked the JRE settings on my eclipse and it uses the correct version. Can anyone please give your valuable suggestion/advice to my issue.

Thank you in advance.

Thanks
V
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That error message means that you are trying to run a class file that was compiled on a newer version of the JDK on an older version of the JRE. For example, you cannot run classes compiled for Java 5 on Java 1.4 - you'll get an UnsupportedClassVersionError if you try that.

Which version(s) of Java are you using, and are you sure that all the classes you are using are compiled for the Java version that you're running the program on?

I recommend to always use the JDK that your system needs to run on - for example, if your production system uses Java 5, use JDK 5 (don't try to use JDK 6 and setting output to Java 5 compatible, because that will not catch the usage of classes in the standard API that only exist in Java 6).
 
Vaideeswaran Natarajan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Jesper.

I am sure the code is getting compiled with jdk1.5 and executed with jre1.5. I am using eclipse and when I right click the preferences it shows me that it uses jre 1.5. I am also using other jars will that give any issues.

Is there any other way to fix this issue using eclipse.

Adding to this I am working on couple of other projects in the same workspace but others seem to work with no issues. This puts me into more trouble.


Thank you for your help.

Thanks
V
 
Sheriff
Posts: 22573
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vaideeswaran Natarajan wrote:I am also using other jars will that give any issues.


And are all those JAR files compiled for Java 5.0 or before?

Is there any other way to fix this issue using eclipse.


The issue is completely unrelated to Eclipse.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All library dependencies must also satisfy the JRE version requirements. Check your path--*something* you're trying to run is compiled with a version of Java higher than the one you're trying to run it with.
 
reply
    Bookmark Topic Watch Topic
  • New Topic