aspose file tools*
The moose likes Beginning Java and the fly likes Error when running a java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error when running a java program" Watch "Error when running a java program" New topic
Author

Error when running a java program

Vinnibabu singu
Ranch Hand

Joined: Aug 19, 2009
Posts: 30
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

Joined: Feb 23, 2009
Posts: 1183
I'm pretty sure it means you compiled your code with Java 5 and try to run it with Java 6.


JDBCSupport - An easy to use, light-weight JDBC framework -
Anshul Agrawal
Greenhorn

Joined: Jul 15, 2008
Posts: 19
yes.. thats right.
Compile your code with Java 1.6 only


Regards
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14150
    
  18

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1763
    
    7

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:



Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Vinnibabu singu
Ranch Hand

Joined: Aug 19, 2009
Posts: 30
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

Joined: Oct 13, 2005
Posts: 38840
    
  23
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

Joined: Aug 19, 2009
Posts: 30
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

Joined: Sep 29, 2008
Posts: 12617

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
Sheriff

Joined: Sep 28, 2004
Posts: 18836
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Vinnibabu singu
Ranch Hand

Joined: Aug 19, 2009
Posts: 30
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

Joined: Oct 13, 2005
Posts: 38840
    
  23
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

Joined: Sep 29, 2008
Posts: 12617

If it's running the wrong Java version then your path cannot possibly be correct.
Vinnibabu singu
Ranch Hand

Joined: Aug 19, 2009
Posts: 30
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

Joined: Oct 13, 2005
Posts: 38840
    
  23
You're welcome

I have heard about Oracle doing that to other people too.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error when running a java program