Results 1 to 11 of 11
  1. #1
    Atticus is offline Member
    Join Date
    Aug 2011
    Posts
    4
    Rep Power
    0

    Default Could not find or load main class: c:\java\HelloWorldApp

    The title of this post is the error that appeared when I attempted to run the Hello World application as outlined in the Java Tutorials.

    My source file was HelloWorldApp.java (cut and pasted from the tutorial)

    I compiled it with the command : javac HelloWorldApp.java

    It produced a file HelloWorldApp.class

    I then attempted to run the application with the command : java HelloWorldApp

    It then produced the above error. I am aware that this particular problem was the subject of another posting but I cannot figure out what the proposed solution was. Can anyone help?

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    Java Code:
    java -cp . HelloWorldApp
    Try the above command (make sure you get the spaces correct). If it works then read about classpath.

  3. #3
    Atticus is offline Member
    Join Date
    Aug 2011
    Posts
    4
    Rep Power
    0

    Default

    I used the command : java -cp . HelloWorldApp

    However, the error appeared exactly as before.

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    In that case your HelloWorldApp class is not in that directory.

  5. #5
    Atticus is offline Member
    Join Date
    Aug 2011
    Posts
    4
    Rep Power
    0

    Default

    Hi Junky

    Thank you for being patient.

    The file HelloWorldApp.class resides in C:\java

    I abbreviated the command for purposes of clarity.

    The full command was C:\Program Files\java\jdk1.7.0\bin\java - cp . C:\java\HelloWorldApp

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    Go to the directory where you .class file is and type the command to run your program.

  7. #7
    chinna is offline Member
    Join Date
    Jul 2011
    Posts
    14
    Rep Power
    0

    Default

    please share your code...

  8. #8
    Atticus is offline Member
    Join Date
    Aug 2011
    Posts
    4
    Rep Power
    0

    Default

    Hi Junky,

    Problem solved
    Both instructions - java HelloWorldApp and java -cp . HelloWorldApp now work.
    Apparent problem was that the instructions would not tolerate a full description of where the HelloWorldApp class file resided

    A curiosity : I used a DOS PATH statement (as used in autoexec.bat files) to pick up the location of java.exe and javac.exe and make them available in any directory. Is this how it is usually done nowadays?

    Thanks again!

  9. #9
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,513
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Atticus View Post
    A curiosity : I used a DOS PATH statement (as used in autoexec.bat files) to pick up the location of java.exe and javac.exe and make them available in any directory. Is this how it is usually done nowadays?
    Remember: javac compiles files and java runs classes; the fact that those classes can be stored in files is coincidental. java uses the current working directory as a classpath (so -cp . is not necessary on a MS Windows system). It depends on the classloader where and how classes are found; the 'normal' system class loader can find the classes in files or in .jar file entries but nothing forbids other class loaders to load classes from databases or by emailing some super user and asking them to send the class over the wire. The classpath is just used by the default class loader and is a list of directories and .jar files that have to be searched for class files. Package names in class names are mapped to subdirectories.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  10. #10
    kd7vea is offline Member
    Join Date
    Apr 2011
    Posts
    9
    Rep Power
    0

    Default Re: Could not find or load main class: c:\java\HelloWorldApp

    I just wanted to chime in here, and say that your response helped me. I have been fighting with my classpath trying to get it right, but atleast now I know that everything else worked.
    Thanks
    Jake

  11. #11
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default Re: Could not find or load main class: c:\java\HelloWorldApp

    What's with waking the zombies? Closing this old, weary thread.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 29
    Last Post: 02-02-2012, 08:23 PM
  2. Replies: 5
    Last Post: 09-16-2011, 07:01 AM
  3. Could not find main class
    By Karenthian in forum New To Java
    Replies: 7
    Last Post: 03-30-2011, 03:02 PM
  4. Could not find main class
    By yetty4ever in forum New To Java
    Replies: 7
    Last Post: 02-16-2011, 07:38 PM
  5. Could not find main class
    By Andyj in forum New To Java
    Replies: 2
    Last Post: 10-06-2009, 12:47 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
  •