Results 1 to 3 of 3
- 07-04-2012, 04:51 PM #1
Member
- Join Date
- Jul 2012
- Posts
- 2
- Rep Power
- 0
Java set up in Linux and Hello World
I have seen many questions about getting Hello World to work.
I have a similar problem: I used thsi code in my text editor in Ubuntu -
"public class MainTest {
public static void main(String[] args) {
System.out.println("Hello World");
}
} "
-I saved it as MainTest.java in my /home/me/ directory
-then complied it with "javac MainTest.java" to create the .class file
-then attempted to run it with "java MainTest" and also "java MainTest.java" both of which failed with error messages as follows;
Exception in thread "main" java.lang.UnsupportedClassVersionError: MainTest : 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(Secure ClassLoader.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.j ava:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:3 21)
at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:2 66)
Could not find the main class: MainTest. Program will exit.
-At this point there seem to be 3 files in the directory: Maintest.java , Maintest.class and Maintest.java~.
- I have tried changing the CLASSPATH to the working directory, using the CLASSPATH and -cp options in the "java" command line instruction, entering and omitting the .java file type but nothing works.
Advice required please!
- 07-04-2012, 05:35 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: Java set up in Linux and Hello World
Nothing to do with CLASSPATH, indeed you do not (nor should ever use) that.
It has everything to do with you having two versions of Java on your system.
A 1.7 JDK and a 1.6 JRE.Please do not ask for code as refusal often offends.
- 07-04-2012, 05:46 PM #3
Member
- Join Date
- Jul 2012
- Posts
- 2
- Rep Power
- 0
Re: Java set up in Linux and Hello World
Hi Tolls, You are right.
I googled the "Exception in Thread" error message and realsied it was because there were multiple versions of Java. I managed to find a piece of code in Ubuntu documentation that, once installed, allowed me to choose which version of Java runs. I selected the latest version and the code ran.
Thanks for your help and all the forum users whose comments pointed me in this directiopn!
Similar Threads
-
Java world generator-real world with people and stuff
By conker5295 in forum Jobs OfferedReplies: 2Last Post: 02-23-2012, 01:22 PM -
hello java world!
By Stephenmak in forum Java SoftwareReplies: 2Last Post: 09-23-2009, 05:29 AM -
[SOLVED] Windows Linux conflict - TrayIcon image not display in Linux
By Eranga in forum Advanced JavaReplies: 6Last Post: 04-08-2009, 04:05 AM -
Hello World in linux returns undefined reference to `main' collect2: ld return
By phil128 in forum New To JavaReplies: 5Last Post: 04-06-2009, 10:10 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks