Results 1 to 20 of 21
- 08-07-2011, 08:48 AM #1
Member
- Join Date
- May 2011
- Posts
- 14
- Rep Power
- 0
Doesn't returning the localhost IP address
Hi! I'm new to Java as well as Linux. well, I've written a program to return the localhost IP address as describes bellow
After that I compiled the code successfully but once I tried to run the program it bugs asJava Code:import java.net.*; class pg1 { public static void main (String[] args) throws UnknownHostException { InetAddress ia = InetAddress.getLocalHost (); System.out.println (ia); } }
ricky@ricky-Rev-1-0:~/Desktop/java$ javac pg1.java
ricky@ricky-Rev-1-0:~/Desktop/java$ java pg1
Exception in thread "main" java.lang.UnsupportedClassVersionError: pg1 : 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: pg1. Program will exit.
I ran the same code in Windows OS successfully.
Could anyone help me to solve the problem?Last edited by sunde887; 08-07-2011 at 09:36 AM. Reason: Added code tags, [code]...[/code]
- 08-07-2011, 08:59 AM #2
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
Last edited by Hibernate; 08-07-2011 at 08:59 AM. Reason: Too big qoute
Ex animo! Hibernate
Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.
- 08-07-2011, 09:02 AM #3
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
Are you using Java 7 or Java 6.
Maybe Java 7 is more strict in have the class public, I can't get Java 7 to work, Java 6 does not seem to require it.Ex animo! Hibernate
Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.
- 08-07-2011, 09:06 AM #4
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
Off topic: As you are new to Linux I would suggest not to use GNOME 3 or Unity, I think they will either kill you, make you kill yourself or make you kill GNU/Linux. Use GNOME 2 or KDE.
Ex animo! Hibernate
Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.
- 08-07-2011, 09:08 AM #5
Member
- Join Date
- May 2011
- Posts
- 14
- Rep Power
- 0
I tried with "public class pg1"
It doesn't work so.
- 08-07-2011, 09:09 AM #6
Member
- Join Date
- May 2011
- Posts
- 14
- Rep Power
- 0
I'm using Java 7
- 08-07-2011, 09:11 AM #7
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
Humm...
Is your Java installation a clean installation or an update?
How did you install Java?
What is the output of (run in terminal)?:
Java Code:update-alternatives --display java
Ex animo! Hibernate
Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.
- 08-07-2011, 09:11 AM #8
Member
- Join Date
- May 2011
- Posts
- 14
- Rep Power
- 0
Well I'm still using GNOME 3.1.4 but what's wrong with GNOME 3?
- 08-07-2011, 09:14 AM #9
Member
- Join Date
- May 2011
- Posts
- 14
- Rep Power
- 0
Is it right?
ricky@ricky-Rev-1-0:~/Desktop/java$ update-alternatives --display java
java - auto mode
link currently points to /usr/lib/jvm/java-6-openjdk/jre/bin/java
/usr/lib/jvm/java-6-openjdk/jre/bin/java - priority 1061
slave java.1.gz: /usr/lib/jvm/java-6-openjdk/jre/man/man1/java.1.gz
/usr/lib/jvm/java-7-openjdk/jre/bin/java - priority 1051
slave java.1.gz: /usr/lib/jvm/java-7-openjdk/jre/man/man1/java.1.gz
Current 'best' version is '/usr/lib/jvm/java-6-openjdk/jre/bin/java'
- 08-07-2011, 09:15 AM #10
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
- 08-07-2011, 09:19 AM #11
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
So you are really using Java 6 and not Java 7.
You can use the command
to configure to use either Java 6 or Java 7.Java Code:update-alternatives --config #
Replace # with java, javac, jar and then javadoc.
(and other Java tools I do not think you will be using for a while like javah and javap).Ex animo! Hibernate
Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.
- 08-07-2011, 09:29 AM #12
Member
- Join Date
- May 2011
- Posts
- 14
- Rep Power
- 0
Originally Posted by Hibernate's Avatar
Hibernate
So you are really using Java 6 and not Java 7.
You can use the command
Code:
update-alternatives --config #
to configure to use either Java 6 or Java 7.
Replace # with java, javac, jar and then javadoc.
(and other Java tools I do not think you will be using for a while like javah and javap).
oot@ricky-Rev-1-0:/home/ricky# update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 auto mode
1 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 manual mode
2 /usr/lib/jvm/java-7-openjdk/jre/bin/java 1051 manual mode
Press enter to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/java-7-openjdk/jre/bin/java to provide /usr/bin/java (java) in manual mode.
did I select the correct one?
- 08-07-2011, 09:34 AM #13
Member
- Join Date
- May 2011
- Posts
- 14
- Rep Power
- 0
and WOW! My program is working, it returns the IP.
ricky@ricky-Rev-1-0:~/Desktop/java$ javac pg1.java
ricky@ricky-Rev-1-0:~/Desktop/java$ java pg1
ricky-Rev-1-0/127.0.1.1
Its good.
But I don't understand what is just append? Why its running now?
- 08-07-2011, 10:05 AM #14
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
I would guess that you have complied with Java 7 and executed with Java 6 meaning that you ran on a version of Java older (in major version) then the program was compiled with
making it incompatible.Ex animo! Hibernate
Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.
- 08-07-2011, 10:28 AM #15
Member
- Join Date
- May 2011
- Posts
- 14
- Rep Power
- 0
Thank you! Thanks helping.
- 08-07-2011, 10:39 AM #16
Member
- Join Date
- May 2011
- Posts
- 14
- Rep Power
- 0
Oh yeah, as u mentioned about GNOME 3, I got another problem with GNOME 3 that whenever I try to install Fedora 15 GNOME 3 (x86 or x86_64) in my pc (lenovo Y560, I've tried in Dell XPS also) it messaged as "GNOME 3 failed to load. Your HD is not able load GMOME 3". Did you ever face such problem (but in case of ubuntu 11.10 alpha 3 with GNOME 3 load properly).
- 08-08-2011, 05:23 AM #17
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
No I never faced any problems, but I'm using Arch Linux. (If you decide to test Arch Linux, be aware that is it a nuclear playground for geeks and you should test it on a virtual computer first and save an installation manual which you can access during installation on a physical computers.)
It sounds weird that your hard drive should fail to load GNOME 3.Ex animo! Hibernate
Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.
- 08-08-2011, 07:35 AM #18
Member
- Join Date
- May 2011
- Posts
- 14
- Rep Power
- 0
Not hard drive it was hardware, I think, the message points to graphics card or HD accelerator.
- 08-08-2011, 10:31 AM #19
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Summary:
A ClassVersion error is entirely down to you compiling in one version and then attempting to run the code in an earlier version of Java.
In your case it was compiled under 7 and you tried to run under 6.
48 is 1.4, 49 is 1.5, 50 is Java 6, and 51 is Java 7.
- 08-08-2011, 10:40 PM #20
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
Similar Threads
-
configuring localhost, working with IBM RAD
By clipod in forum EclipseReplies: 6Last Post: 12-03-2010, 04:23 PM -
jboss server, localhost as ip...
By Sno in forum EclipseReplies: 1Last Post: 06-23-2010, 08:30 PM -
java-vnc connection to localhost
By pdc124 in forum Java AppletsReplies: 0Last Post: 07-26-2009, 01:23 PM -
How to getrid of Localhost in SOAP:Address location (runtime) - need help
By nilantha in forum Advanced JavaReplies: 2Last Post: 03-22-2009, 06:41 PM -
connecting to a wsdl on localhost
By david99world in forum EclipseReplies: 0Last Post: 01-23-2009, 10:25 PM


3Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks