Results 1 to 10 of 10
  1. #1
    fogus is offline Member
    Join Date
    Mar 2008
    Posts
    43
    Rep Power
    0

    Default Help with "hello world"

    After 3 hours I have decided to turn this over to the experts.

    The helloworld.java program is:

    Java Code:
    public class helloworld
    {
       public static void main(String args[])
       {
          System.out.println("hello world");
       }
    }
    The result is:
    Java Code:
    >java helloworld
    java.lang.NoClassDefFoundError: helloworld
    Caused by: java.lang.ClassNotFoundException: helloworld
    	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)
    Exception in thread "main" >Exit code: 1
    I am using SciTE as an editor, but I get the same result in the command prompt, when I use:
    Java Code:
    command.compile.*.java=javac $(FileNameExt)
    command.build.*.java=javac *.java
    command.go.*.java=java $(FileName)
    I think this has something to do with my "environment variables"; JCreator can run this program just fine.

    Here are the relavent environment variables:
    System Variables\CLASSPATH:
    C:\Program Files\Java\jdk1.6.0_04\src.jar;
    C:\Program Files\Java\jdk1.6.0_04\lib\dt.jar;
    C:\Program Files\Java\jdk1.6.0_04\lib\tools.jar;
    C:\Program Files\Java\jdk1.6.0_04\jre\lib\il8n.jar;
    C:\Program Files\Java\jdk1.6.0_04\jre\lib\jaws.jar;
    C:\Program Files\Java\jdk1.6.0_04\jre\lib\rt.jar;
    C:\Program Files\Java\jdk1.6.0_04\jre\demo\sound\JavaSound.ja r;
    C:\Program Files\Java\jdk1.6.0_04\demo\jfc\SwingSet2\SwingSet 2.jar;
    C:\Program Files\Java\jdk1.6.0_04\demo\jfc\SwingApplet\SwingA pplet.jar;
    C:\Program Files\Java\jdk1.6.0_04\;
    C:\Program Files\Java\jdk1.6.0_04\Bin;
    C:\Program Files\Java\jdk1.6.0_04\Lib;
    (all on one line, of course)

    User Variables\PATH:
    C:\Program Files\Java\jdk1.6.0_04\bin

    However, when I run SciTE pointed at:

    Java Code:
    command.compile.*.java=C:\Program Files\Java\jdk1.6.0_04\bin\javac $(FileNameExt)
    command.build.*.java=C:\Program Files\Java\jdk1.6.0_04\bin\javac *.java
    command.go.*.java=C:\Program Files\Java\jdk1.6.0_04\bin\java $(FileName)
    I get a slightly different message:


    Java Code:
    java.lang.NoClassDefFoundError: helloworld
    Caused by: java.lang.ClassNotFoundException: helloworld
    	at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
    Exception in thread "main" >Exit code: 1
    1. Anyone care to clue me in on why the default installation of JDK does not work with the command prompt?
    2. What should my environment variables be?

  2. #2
    Menre is offline Member
    Join Date
    Feb 2008
    Posts
    79
    Rep Power
    0

    Default

    Hi,

    I have noticed something wrong in your coding. In your programme you wrote the line below

    public static void main(String args[])

    It should be written the way below

    public static void main(String[] args )

    I hope this solves your problem.

    Regards,
    Menre

  3. #3
    neethur is offline Member
    Join Date
    Mar 2008
    Posts
    1
    Rep Power
    0

    Default

    I have lost my httpservlet.jar file from my system, can anyone help me by sending one to my id "neethmohan@yahoo.com"

  4. #4
    Jman is offline Member
    Join Date
    Dec 2007
    Posts
    17
    Rep Power
    0

    Default

    Hi Fogus

    I think your problem is that you have not yet compiled your code. I say think because you just mention running java helloworld. If I am wrong please forgive me. But here goes anyway. Try the following
    1. save the code as helloworld.java
    2. cd to the directory you stored the helloworld.java file
    3. run javac helloworld.java
    4. then run java helloworld
    this should work.

  5. #5
    fogus is offline Member
    Join Date
    Mar 2008
    Posts
    43
    Rep Power
    0

    Default

    You know, Jman, I had tried those steps before, but for some reason things just started to work all of a sudden. Perhaps my environment variables just didn't kick in for a while.

    Thanks everyone; the issue has been solved.

  6. #6
    Codapalpjonna is offline Member
    Join Date
    Dec 2008
    Location
    US
    Posts
    2
    Rep Power
    0

    Default iixkhocxzuqkwdcdhzrofufvelcptbanmowhello guys need advice

    qxfskkdzgpgyaujawell, hi admin adn people nice forum indeed. how's life? hope it's introduce branch ;)

  7. #7
    anandmohans is offline Member
    Join Date
    Sep 2008
    Posts
    2
    Rep Power
    0

    Default

    To execute any class, the CLASSPATH variable must point to the location where .class file is located. Typically, when you compile & execute your code using some IDE, the class is made available to JVM by the IDE. In other cases you will have to ensure that class file is present at the location specified by CLASSPATH.
    For more details, you can refer to following link:
    j2eeconcepts.com/j2eeconcepts/pages/java/general/classpath.htm

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    sorry to disappoint you anandmohans, but the ones who matter, in particular fogus, are no longer reading this thread as it is a zombie thread that has been resurrected for unknown reasons by Codapalpjonna, who I suspect is a troll.

  9. #9
    fogus is offline Member
    Join Date
    Mar 2008
    Posts
    43
    Rep Power
    0

    Default

    The funny thing is that I am having this problem again right now.

    I have tried all the usual things and I set my CLASSPATH to:

    C:\Program Files\Java\jdk1.6.0_10\src.jar;C:\Program Files\Java\jdk1.6.0_10\lib\dt.jar;C:\Program Files\Java\jdk1.6.0_10\lib\tools.jar;C:\Program Files\Java\jdk1.6.0_10\jre\lib\il8n.jar;C:\Program Files\Java\jdk1.6.0_10\jre\lib\jaws.jar;C:\Program Files\Java\jdk1.6.0_10\jre\lib\rt.jar;C:\Program Files\Java\jdk1.6.0_10\jre\demo\sound\JavaSound.ja r;C:\Program Files\Java\jdk1.6.0_10\demo\jfc\SwingSet2\SwingSet 2.jar;C:\Program Files\Java\jdk1.6.0_10\demo\jfc\SwingApplet\SwingA pplet.jar;C:\Program Files\Java\jdk1.6.0_10\;C:\Program Files\Java\jdk1.6.0_04\Bin;C:\Program Files\Java\jdk1.6.0_10\Lib;

    1. Any ideas?
    2. Why doesn't python have this problem?

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    this is just too weird!

    anyway, are you talking about your OS environment's classpath, if so, don't mess with it. Instead compile with the -cp switch. I usually use -cp . or something similar.

Similar Threads

  1. Hwlp with "Open", "Save", "Save as..."
    By trill in forum New To Java
    Replies: 3
    Last Post: 11-02-2010, 09:26 AM
  2. Replies: 1
    Last Post: 03-14-2008, 02:51 PM
  3. Replies: 1
    Last Post: 07-27-2007, 10:59 PM
  4. Replies: 1
    Last Post: 07-25-2007, 10:55 PM
  5. Replies: 1
    Last Post: 07-16-2007, 06:32 AM

Posting Permissions

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