Page 1 of 2 12 LastLast
Results 1 to 20 of 21
Like Tree3Likes

Thread: Doesn't returning the localhost IP address

  1. #1
    rootnet47 is offline Member
    Join Date
    May 2011
    Posts
    14
    Rep Power
    0

    Exclamation 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

    Java Code:
    import java.net.*;
    
    class pg1
    {
    	public static void main (String[] args) throws UnknownHostException
    	{
    		InetAddress ia = InetAddress.getLocalHost ();
    		System.out.println (ia);
    	}
    }
    After that I compiled the code successfully but once I tried to run the program it bugs as

    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]

  2. #2
    Hibernate's Avatar
    Hibernate is offline Senior Member
    Join Date
    Dec 2010
    Location
    Stockholm, Sweden
    Posts
    222
    Blog Entries
    9
    Rep Power
    4

    Default

    Quote Originally Posted by rootnet47 View Post
    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

    import java.net.*;

    class pg1
    {
    public static void main (String[] args) throws UnknownHostException
    {
    InetAddress ia = InetAddress.getLocalHost ();
    System.out.println (ia);
    }
    }

    After that I compiled the code successfully but once I tried to run the program it bugs as

    ricky@ricky-Rev-1-0:~/Desktop/java$ javac pg1.java
    [⋅⋅⋅]
    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?

    Oi, it works: Zenith/127.0.1.1
    (Yes, my computer is called Zenith because it is above yours. (my virtual ones are called Nadir))

    But you should have public on the class: public class pg1
    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.

  3. #3
    Hibernate's Avatar
    Hibernate is offline Senior Member
    Join Date
    Dec 2010
    Location
    Stockholm, Sweden
    Posts
    222
    Blog Entries
    9
    Rep Power
    4

    Default

    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.

  4. #4
    Hibernate's Avatar
    Hibernate is offline Senior Member
    Join Date
    Dec 2010
    Location
    Stockholm, Sweden
    Posts
    222
    Blog Entries
    9
    Rep Power
    4

    Default

    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.

  5. #5
    rootnet47 is offline Member
    Join Date
    May 2011
    Posts
    14
    Rep Power
    0

    Default

    I tried with "public class pg1"
    It doesn't work so.

  6. #6
    rootnet47 is offline Member
    Join Date
    May 2011
    Posts
    14
    Rep Power
    0

    Default

    I'm using Java 7

  7. #7
    Hibernate's Avatar
    Hibernate is offline Senior Member
    Join Date
    Dec 2010
    Location
    Stockholm, Sweden
    Posts
    222
    Blog Entries
    9
    Rep Power
    4

    Default

    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.

  8. #8
    rootnet47 is offline Member
    Join Date
    May 2011
    Posts
    14
    Rep Power
    0

    Default

    Well I'm still using GNOME 3.1.4 but what's wrong with GNOME 3?

  9. #9
    rootnet47 is offline Member
    Join Date
    May 2011
    Posts
    14
    Rep Power
    0

    Default

    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'

  10. #10
    Hibernate's Avatar
    Hibernate is offline Senior Member
    Join Date
    Dec 2010
    Location
    Stockholm, Sweden
    Posts
    222
    Blog Entries
    9
    Rep Power
    4

    Default

    Quote Originally Posted by rootnet47 View Post
    Well I'm still using GNOME 3.1.4 but what's wrong with GNOME 3?
    Just very uncomfortably and working it gets every inefficient.
    Also features I think very high of have been disabled/removed.
    Ex animo! Hibernate
    Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.

  11. #11
    Hibernate's Avatar
    Hibernate is offline Senior Member
    Join Date
    Dec 2010
    Location
    Stockholm, Sweden
    Posts
    222
    Blog Entries
    9
    Rep Power
    4

    Default

    Quote Originally Posted by rootnet47 View Post
    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'

    So you are really using Java 6 and not Java 7.

    You can use the command
    Java 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).
    rootnet47 likes this.
    Ex animo! Hibernate
    Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.

  12. #12
    rootnet47 is offline Member
    Join Date
    May 2011
    Posts
    14
    Rep Power
    0

    Default

    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?

  13. #13
    rootnet47 is offline Member
    Join Date
    May 2011
    Posts
    14
    Rep Power
    0

    Default

    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?

  14. #14
    Hibernate's Avatar
    Hibernate is offline Senior Member
    Join Date
    Dec 2010
    Location
    Stockholm, Sweden
    Posts
    222
    Blog Entries
    9
    Rep Power
    4

    Default

    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.

  15. #15
    rootnet47 is offline Member
    Join Date
    May 2011
    Posts
    14
    Rep Power
    0

    Default

    Thank you! Thanks helping.

  16. #16
    rootnet47 is offline Member
    Join Date
    May 2011
    Posts
    14
    Rep Power
    0

    Default

    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).

  17. #17
    Hibernate's Avatar
    Hibernate is offline Senior Member
    Join Date
    Dec 2010
    Location
    Stockholm, Sweden
    Posts
    222
    Blog Entries
    9
    Rep Power
    4

    Default

    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.

  18. #18
    rootnet47 is offline Member
    Join Date
    May 2011
    Posts
    14
    Rep Power
    0

    Default

    Not hard drive it was hardware, I think, the message points to graphics card or HD accelerator.

  19. #19
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default

    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.
    DarrylBurke and rootnet47 like this.

  20. #20
    Hibernate's Avatar
    Hibernate is offline Senior Member
    Join Date
    Dec 2010
    Location
    Stockholm, Sweden
    Posts
    222
    Blog Entries
    9
    Rep Power
    4

    Default

    That is some weird numbering (not really, but it should be improved.).
    Ex animo! Hibernate
    Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.

Page 1 of 2 12 LastLast

Similar Threads

  1. configuring localhost, working with IBM RAD
    By clipod in forum Eclipse
    Replies: 6
    Last Post: 12-03-2010, 04:23 PM
  2. jboss server, localhost as ip...
    By Sno in forum Eclipse
    Replies: 1
    Last Post: 06-23-2010, 08:30 PM
  3. java-vnc connection to localhost
    By pdc124 in forum Java Applets
    Replies: 0
    Last Post: 07-26-2009, 01:23 PM
  4. Replies: 2
    Last Post: 03-22-2009, 06:41 PM
  5. connecting to a wsdl on localhost
    By david99world in forum Eclipse
    Replies: 0
    Last Post: 01-23-2009, 10:25 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •