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
posted
0
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: 18
posted
0
yes.. thats right.
Compile your code with Java 1.6 only
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.
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
posted
0
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: 32689
4
posted
0
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
posted
0
It is giving java 1.4
But I installed java 1.6 and my control panel confirms it.
Why might be the problem?
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.
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.
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: 32689
4
posted
0
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.