Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Error when running a java program

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hii...
I have jdk 1.6 installed in my system.
It was doing well initially.All of a sudden there is an error when trying to run even a small java program
the error is as follows.
Exception in thread "main" java.lang.UnsupportedClassVersionError:TDemo<Unsupported major.minor version 50.0>
at java.lang.ClassLoader.defineClass0(Native Method)
at java.......................................

what reason might have caused the error?
thanks for the reply in advance
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm pretty sure it means you compiled your code with Java 5 and try to run it with Java 6.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes.. thats right.
Compile your code with Java 1.6 only
 
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

Sebastian Janisch wrote:I'm pretty sure it means you compiled your code with Java 5 and try to run it with Java 6.


You probably mean that the other way around: the code was compiled with Java 6, and you're trying to run it with Java 5.

Java is downward compatible: newer versions can run class files compiled with older versions. But it is not upward compatible - older versions cannot (normally) run class files compiled with newer versions.

Compile your code with Java 5 if it needs to run on a Java 5 JRE.
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The mapping between the major / minor version in the magic number of the class file and the Java platform / compiler version might be useful for future reference:

 
Vinnibabu singu
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is only one version installed in my system i.e., java 1.6
I compiled it in the command prompt and tried to run it as soon as it is compiled
I dint make any changes of the version.
The same code is running successfully when i tried to run it in netbeans IDE instead of command prompt.
 
Marshal
Posts: 76468
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is quite possible there is in fact an older Java runtime installed. Go to the terminal and try this instruction

java -version

See whether that gives you 1.6----
 
Vinnibabu singu
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is giving java 1.4
But I installed java 1.6 and my control panel confirms it.
Why might be the problem?
 
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
It'll run the first java it finds on your path. Just because you install a new version of Java doesn't mean older versions are uninstalled, or the public JRE was replaced.
 
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vinnibabu singu wrote:It is giving java 1.4
But I installed java 1.6 and my control panel confirms it.
Why might be the problem?



Your OS may have Java preinstalled -- and you didn't set the PATH variables correctly, so it is running the default one. As for NetBeans, the IDE makes sure it uses the same compiler and JVM version.

Henry
 
Vinnibabu singu
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried removing my classpath and path variable and system is still compiling the java programs
using the java 1.4 version.It never happened before.
Even if set the classpath and path to jdk 1.6 correctly its using the same java 1.4 version.
What am i supposed to do now?
 
Campbell Ritchie
Marshal
Posts: 76468
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't set a classpath; that usually causes more trouble later on.
You will have to restore your PATH otherwise lots of programs will fail to run.
David Newton told you what the problem was; you ought to have put the Java6 installation before the Java1.4 in the PATH.
 
David Newton
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
If it's running the wrong Java version then your path cannot possibly be correct.
 
Vinnibabu singu
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks everyone..I got it
actually i installed oracle 10g in my system recently and it installed java 1.4 into my system.
this caused the problem.
 
Campbell Ritchie
Marshal
Posts: 76468
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome

I have heard about Oracle doing that to other people too.
 
Get me the mayor's office! I need to tell her about this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic