Question

Possible Duplicate:
Java error: Bad version number in .class file error when trying to run Cassandra on OS X

I am not sure i am doing anything wrong with this basic hello world program. Have no idea why does this throw errors.

I have saved the file as test.java.

public class test {
    public static void main(String[] args) {
        System.out.println("Hello!");
    }

    /*public static void sop(String str) {
        System.out.println(str);
    }*/
}

When i compile it with javac test.java, it compiles successfully, but when i try to run it by using java test, it gives the following error:

C:\Users\admin\Desktop>java test
Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)

The Java bin directory is added in System path. Would appreciate any pointers.

Java directories in the system path are as follows:

C:\Program Files\Java\jdk1.6.0_31\bin;C:\Program Files\Java\jre6\lib;

The java/javac versions:

C:\Users\admin\Desktop>java -version
java version "1.5.0_12"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_12-b04)
Java HotSpot(TM) Client VM (build 1.5.0_12-b04, mixed mode, sharing)

C:\Users\admin\Desktop>javac -version
javac 1.6.0_31

Thanks.

Was it helpful?

Solution

Your java compiler is version 1.6.0 and your java executable environment is version 1.5.0.

The error is to tell you that your java executable to too new for the java executable environment.

To solve your problem you need to update your java environment (or downgrade your java compiler).

OTHER TIPS

It could also be that your test class is improperly titled.

Class names should be capitalized according the ANSI standard.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top