Java Problem java.lang.UnsupportedClassVersionError

Asked by a-r-k-i-b-o-t-t

I already changed my Java Version from Gnu to the Sun Version
java version "1.5.0_11"
Java(TM) 2 Runtime Environment, Standard Edition

I still always get an Error like this, if i try to run a Simple Hello World Application.

Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
        at java.lang.ClassLoader.defineClass2(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:719)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:160)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:254)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

Does anyone know, why this occurs?

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
a-r-k-i-b-o-t-t
Solved:
Last query:
Last reply:
Revision history for this message
a-r-k-i-b-o-t-t (arkibott-ray) said :
#1

A way better Question: How can i fix it? :)

Revision history for this message
Raúl González Duque (zootropo) said :
#2

Try to recompile the java file with Sun's javac:
javac MyClass.java

Revision history for this message
a-r-k-i-b-o-t-t (arkibott-ray) said :
#3

Unfortunately this didn't make any difference. I changed my java sdk version. Also not solving this. Just a slightly different Error Message:

foo@bar:~/NetBeans/javaRegEx/src/javaregex$ ls
Main.java
foo@bar:~/NetBeans/javaRegEx/src/javaregex$ javac Main.java
foo@bar:~/NetBeans/javaRegEx/src/javaregex$ ls
Main.class Main.java
foo@bar:~/NetBeans/javaRegEx/src/javaregex$ java Main
Exception in thread "main" java.lang.UnsupportedClassVersionError: Main (Unsupported major.minor version 50.0)
        at java.lang.ClassLoader.defineClass0(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)

foo@bar:~/NetBeans/javaRegEx/src/javaregex$ java -version
java version "1.4.2-02"
Java(TM) 2 Runtime Environment, Standard Edition (build Blackdown-1.4.2-02)
Java HotSpot(TM) Client VM (build Blackdown-1.4.2-02, mixed mode)

Revision history for this message
a-r-k-i-b-o-t-t (arkibott-ray) said :
#4

Well i copied this Example code from a sun Documentation... Maybe this doesn't work:

import java.io.Console;
import java.util.regex.Pattern;
import java.util.regex.Matcher;

Revision history for this message
Ralph Janke (txwikinger) said :
#5

well. your sun java is not called.

you need to execute

 sudo update-alternatives --config java

and then select the sun java version

java -version should then give you the version of the sun java (java version "1.5.0_11")

You also might want to change the priority of the vm by editing the file /etc/jvm and put the line

/usr/lib/jvm/java-1.5.0-sun

in the front of the other lines.

I hope this solves your problem

Revision history for this message
a-r-k-i-b-o-t-t (arkibott-ray) said :
#6

I think i got a Solution for that one:

sudo update-alternatives --config java

AND

sudo update-alternatives --config javac

--> They must be set to the same Java Version.

Revision history for this message
ridhika (ridhika-goel) said :
#7

i am getting the same problem when i am running simple java applications. I have jdk 1.5_08 installed in my system
Tried running this command,but when I am trying to run this in commandprompt...its showing 'sudo' is not recognised as an internal or external command,operable program or batch file. please help me get rid of this problem. Thats why i am not able to run it in eclipse also.

Revision history for this message
chavash (anatoly-mironov) said :
#8

Thank you for this thread. I had the same trouble. But after running
sudo update-alternatives --config java
sudo update-alternatives --config javac
as a-r-k-i-b-o-t-t said and assuring the both use the same Java Version all worked perfectly.