Page 2 of 2 FirstFirst 12
Results 21 to 30 of 30
Like Tree2Likes

Thread: Error: Could not find or load main class HelloWorldApp (HELP)

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

    Default

    If you are using GNU/Linux you could run (e.g. via a terminal):
    echo "alias j='java -cp .'" >> ~/.bashrc

    So that you only need to type:
    j ClassToRun

    But I don't know if you can do something like that in Windows.

    If you know any other language or can compile Java to Exe (there ought to be tools for that) you could make a program valued j that
    runs Java with those parameters. And copy that program to C:/Windows/System32 (I think).


    Edit:
    Ohh, you are running Windows. (I didn't look that up before replying.)
    Ex animo! Hibernate
    Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.

  2. #22
    ProgramHusky is offline Member
    Join Date
    Oct 2011
    Posts
    2
    Rep Power
    0

    Angry Re: Error: Could not find or load main class HelloWorldApp (HELP)

    Thank God pbrockway2
    Thank God pbrockway2
    Why do you need the line to run this
    java -cp . Hello <----whatever the file is
    this example is hello.

    Seriously I have read books and books and setting up the compiler and execution even professors have no idea about. I summoned a LivePerson expert and he had no idea you execute with java -cp . "Filename" WTH. Why isn't this labeled everywhere in books!!!

  3. #23
    ccellist is offline Member
    Join Date
    Oct 2011
    Posts
    2
    Rep Power
    0

    Default Re: Error: Could not find or load main class HelloWorldApp (HELP)

    I'm not sure if this will help anyone, but I ran into this same issue and what happened is I had inadvertently run:

    set CLASSPATH=<some directory>

    in a push code script. It's possible some java installer set CLASSPATH to something without you realizing, which is why it's not finding your newest class. You can verify this by typing

    in Windows:
    echo %CLASSPATH%

    in Linux:
    $ echo $CLASSPATH

    and see if it spits out a directory. If you want to avoid having to run java -cp . <classname> every time and CLASSPATH is set, then the best thing to do is to clear the CLASSPATH environment variable. A warning though, this might have side-effects on code that relies on CLASSPATH to be set to some pre-determined value. In general, Java apps should set and then reset CLASSPATH on their own, but not everyone is neat about their code:

    in Windows:
    set CLASSPATH=

    in Linux:
    $ CLASSPATH=
    $ export CLASSPATH

    This should allow you to run your Java app from within the class directory.

    And yes, this should be in tutorials and books somewhere. Took me a few minutes to figure this one out.

    Cheers!
    Last edited by ccellist; 10-04-2011 at 10:43 PM.
    pbrockway2 likes this.

  4. #24
    ProgramHusky is offline Member
    Join Date
    Oct 2011
    Posts
    2
    Rep Power
    0

    Question Re: Error: Could not find or load main class HelloWorldApp (HELP)

    I am sorry I could not follow the code I followed the logic though. So in a push script language CLASSPATH was set to= C:\Program Files\Java\jdk1.7.0\lib.; What should CLASSPATH be set to?

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

    Default Re: Error: Could not find or load main class HelloWorldApp (HELP)

    What should CLASSPATH be set to?
    I agree with ccellist that CLASSPATH should be unset. There are other ways of doing things, but not using a CLASSPATH environment variable is the least surprising.

    For a while Quicktime was setting this variable and this caused any amount of confusion with people who relied on the "default" classpath which is the current directory except when a CLASSPATH variable has been set.

    -----

    Post #22 contains a little slip - and it is best to be precise about such things.

    The java executable expects, as an argument, the name of a class (not a file), and the javac executable expects the name of a file (not a class). So in

    Java Code:
    java -cp . Hello
    Hello is the name of a class, not a file. For instance if this class were part of a package then that package would appear as part of the class name.

    When you compile you do refer to files:

    Java Code:
    javac -cp . Hello.java
    Note the suffix, .java, which shows that it is a file being referred to here.

    -----

    Both the java executable and the javac executable like to know about the classpath. The classpath is just the place to go looking for classes. To repeat the point made above things are the least surprising if you say what classpath you mean explicitly as part of the command.
    ccellist likes this.

  6. #26
    ccellist is offline Member
    Join Date
    Oct 2011
    Posts
    2
    Rep Power
    0

    Default Re: Error: Could not find or load main class HelloWorldApp (HELP)

    ProgramHusky,

    CLASSPATH should be set to an empty string. If you follow the code I wrote above you should have no trouble. In other words, in Windows type exactly

    CLASSPATH= then hit <enter> and you should be all set. You're making CLASSPATH equal to an empty string, which is as it should be.

    Hope this helps.

  7. #27
    prasunkjha is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Thumbs up Re: Error: Could not find or load main class HelloWorldApp (HELP)

    hi bro,
    just set your classpath to the folder where you .java files you intend to save.
    for this place mouse on my computer icon click on properties then click on advanced than click on environmental variables,check for system variable displayed in new window and double click on classpath and type or copy pest location address of you folder containing .java files.
    then you dont need to use command for run your program c:\ your directory name >java cp . HelloWorldApp
    cp is for classpath only once you set it than no need of it .

    if any body finds it helpful than please let me be known for being happy..

  8. #28
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Error: Could not find or load main class HelloWorldApp (HELP)

    No.
    First off why resurrect a 4 month old thread?
    Second do NOT set the CLASSPATH in the system environments.
    After all, not all your projects are going to be in the same directory.

    Do it properly...use -cp.
    For larger projects (once you've stopped learning the basics), use an IDE, or build tool.

  9. #29
    prasunkjha is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Default Re: Error: Could not find or load main class HelloWorldApp (HELP)

    resurrect ! because i am newbie here and today i got same problem and it ended by using that.
    thanks for your tips.

  10. #30
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: Error: Could not find or load main class HelloWorldApp (HELP)

    There's enough information in this thread already. Any additions are more than likely to be confusing, or just plain wrong.

    Closing the thread.

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

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 2
    Last Post: 09-22-2011, 10:48 PM
  2. runtime error 'could not find main class' ?
    By ruud00000 in forum Java Applets
    Replies: 5
    Last Post: 12-31-2010, 06:58 PM
  3. Replies: 3
    Last Post: 11-11-2010, 09:12 AM
  4. [SOLVED] Could not find the main class: error...
    By bobleny in forum New To Java
    Replies: 21
    Last Post: 03-02-2010, 11:53 AM
  5. Replies: 1
    Last Post: 07-03-2009, 09:41 PM

Posting Permissions

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