Results 1 to 5 of 5
  1. #1
    Goodwater is offline Member
    Join Date
    Mar 2009
    Posts
    2
    Rep Power
    0

    Default Exceptions in thread

    Hi

    I`m having a problem with my first program. In cmd I have written: javac Hallo.java , that was ok, but when I entered: java Hallo , the following message appeared:

    C:\Program Files\Crimson Editor\template>java Hallo
    Exception in thread "main" java.lang.NoClassDefFoundError: Hallo
    Caused by: java.lang.ClassNotFoundException: Hallo
    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)
    Could not find the main class: Hallo. Program will exit.

    If anybody can help I would be grateful

  2. #2
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    Show us the code first :)

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    The runtime is saying that it cannot locate the Hallo class (ie Hallo.class).

    This is because it is not on the classpath you are using. Since you did not specify any classpath on the command line the java executable will use either the value of the CLASSPATH variable if you have one set, or the current directory.

    (The classpath is just a set of locations that the java runtime will use to locate classes.)

    Note (1) the runtime will not do both so if you have a CLASSPATH variable then the current directory will not be searched for classes. (2) Commonly, people don't set the CLASSPATH variable and if it is set they unset it so that it doesn't get in the road of what they want to do.

    It strikes me that the template directory is an odd place for you to put your data files. (Either .java or .class files). I would suggest that you locate the Hallo.java file and move it somewhere sane: on a Windows machine this will be somewhere within the "Documents and settings" folder. Then from within the folder you move the file to you can compile and run with:

    Java Code:
    C:\Documents and Settings\UserName\JavaStuff>javac Hallo.java
    C:\Documents and Settings\UserName\JavaStuff>dir
    C:\Documents and Settings\UserName\JavaStuff>java Hallo
    The "dir" command is just to check that Hallo.class exists where it should. If these commands prove ineffective, post the output when you run them.

  4. #4
    Goodwater is offline Member
    Join Date
    Mar 2009
    Posts
    2
    Rep Power
    0

    Smile

    It worked. Thanks alot:)

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

Similar Threads

  1. Difference between Thread.yield() and Thread.sleep() methods
    By Nageswara Rao Mothukuri in forum New To Java
    Replies: 12
    Last Post: 07-30-2010, 06:37 PM
  2. Need Help With Exceptions
    By maggie_2 in forum New To Java
    Replies: 5
    Last Post: 12-15-2008, 08:12 PM
  3. Replies: 0
    Last Post: 01-28-2008, 08:02 AM
  4. Runtime Exceptions
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-12-2007, 11:31 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
  •