This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error when running a java program

 
Vinnibabu singu
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • 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
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • 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.
 
Anshul Agrawal
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes.. thats right.
Compile your code with Java 1.6 only
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15490
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • 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.
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50246
79
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • 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.
 
Henry Wong
author
Marshal
Pie
Posts: 21506
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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
Sheriff
Pie
Posts: 50246
79
  • Mark post as helpful
  • send pies
  • 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
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • 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
  • 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
Sheriff
Pie
Posts: 50246
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome

I have heard about Oracle doing that to other people too.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic