0

This is my first program, and my first attempt at running it. I am on Ubuntu.

Source Code:

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

And this is the error I get when I try to run it:

Exception in thread "main" java.lang.UnsupportedClassVersionError: printTest : 
                                               Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: printTest. Program will exit.


------------------
(program exited with code: 1)
Press return to continue

EDIT: Okay, this is my JRE version: owner@ubuntu:~$ java -version java version "1.6.0_24" OpenJDK Runtime Environment (IcedTea6 1.11.4) (6b24-1.11.4-1ubuntu0.12.04.1) OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode) owner@ubuntu:~$

But my javac version is: 1.7.0_03

3 Answers 3

2
Exception in thread "main" java.lang.UnsupportedClassVersionError: 

You have runtime JVM version different from Compile time JVM version.

Make sure your classpath points to same JVM version as compile time.

Sign up to request clarification or add additional context in comments.

6 Comments

Is that something to do with the JRE?
I was just about to post my answer when the one new answer message popped up xD
Yes, check your classpath and make sure the JAVA_HOME paths are pointing to same JRE. Are you using any IDE?
@Nambari Yes, well I am using Geany.
I would suggest check JAVA_HOME settings for that IDE. I never worked on it, so I couldn't point you exact location. There may be something related to compiler version setting also, make sure compiler setting also correct.
|
0

There is difference between java version on which you are compiling source code and java version on which you are executing source code.

You are compiling in java 7 and executing in lesser version you need to set JAVA_HOME to java7 only.

Here is how to set JAVA_HOME on Ubantu.

Comments

0

Try writing your program in a IDE. It is much easier because it shows you the errors in your code and you can easily compile it from the same program. Here is the site where you can download a good one http://www.eclipse.org/downloads/packages/eclipse-ide-java-and-dsl-developers/junosr2

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.