Results 1 to 13 of 13
  1. #1
    Cutejeff is offline Member
    Join Date
    Jul 2012
    Location
    Nigeria
    Posts
    7
    Rep Power
    0

    Exclamation Error: Could not find or load main class HelloWorld

    pls how do i solve this error on my java am new here and am also new to leaning java am a computer science i really need to lean it

    this are errors i get

    Java Code:
    Microsoft Windows [Version 6.0.6002]
    Copyright (c) 2006 Microsoft Corporation.  All rights reserved.
    
    C:\Users\hp>cd desktop
    
    C:\Users\hp\Desktop>cd java
    
    C:\Users\hp\Desktop\java>cd student files
    The system cannot find the path specified.
    
    C:\Users\hp\Desktop\java>student files
    'student' is not recognized as an internal or external command,
    operable program or batch file.
    
    C:\Users\hp\Desktop\java>cd Student Files
    The system cannot find the path specified.
    
    C:\Users\hp\Desktop\java>cd StudentFiles
    
    C:\Users\hp\Desktop\java\StudentFiles>cd Ch02
    
    C:\Users\hp\Desktop\java\StudentFiles\Ch02>cd Hello
    
    C:\Users\hp\Desktop\java\StudentFiles\Ch02\Hello>cd Greetings.java
    The directory name is invalid.
    
    C:\Users\hp\Desktop\java\StudentFiles\Ch02\Hello>greetings.java
    Error: Could not find or load main class C:\Users\hp\Desktop\java\StudentFiles\C
    h02\Hello\Greetings.java
    
    C:\Users\hp\Desktop\java\StudentFiles\Ch02\Hello>java Greetings
    Error: Could not find or load main class Greetings
    
    C:\Users\hp\Desktop\java\StudentFiles\Ch02\Hello>java HelloWorld
    Error: Could not find or load main class HelloWorld
    
    C:\Users\hp\Desktop\java\StudentFiles\Ch02\Hello>
    Last edited by DarrylBurke; 07-18-2012 at 09:55 PM. Reason: Removed annoying formatting

  2. #2
    jhuber151 is offline Member
    Join Date
    Jul 2012
    Posts
    55
    Rep Power
    0

    Default Re: Error: Could not find or load main class HelloWorld

    I am not exactly sure what you are trying to do but to run command line prompts for your java program
    1) get to directory of your .java files using cd
    2) use javac nameOfProgram.java
    this compiles it and creates a .class file
    3) now use dir to see if the class file was created
    4) now run java nameOfProgram

    This should let you run your java program from command line

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

    Default Re: Error: Could not find or load main class HelloWorld

    Quote Originally Posted by Cutejeff View Post
    ... am also new to leaning java
    So don't post beginner questions in the Advanced Java section. Moving the thread.

    Also, don't use extra large fonts and all-bold sentences as that makes your post difficult to read. I've edited the post to make it more readable.

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

  4. #4
    Cutejeff is offline Member
    Join Date
    Jul 2012
    Location
    Nigeria
    Posts
    7
    Rep Power
    0

    Default Re: Error: Could not find or load main class HelloWorld

    Quote Originally Posted by jhuber151 View Post
    I am not exactly sure what you are trying to do but to run command line prompts for your java program
    1) get to directory of your .java files using cd
    2) use javac nameOfProgram.java
    this compiles it and creates a .class file
    3) now use dir to see if the class file was created
    4) now run java nameOfProgram

    This should let you run your java program from command line
    pls i"ll love it if u can write the steps so i can follow it thanks for your help

  5. #5
    Cutejeff is offline Member
    Join Date
    Jul 2012
    Location
    Nigeria
    Posts
    7
    Rep Power
    0

    Default Re: Error: Could not find or load main class HelloWorld

    i tried again and got this error

    c:\Program Files\javac>javac Greetings.java
    Greetings.java:8: error: error while writing Greetings: Greetings.class (Access
    is denied)
    public class Greetings
    ^
    1 error

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

    Default Re: Error: Could not find or load main class HelloWorld

    First learn to use your OS. Once you have that down, get back to thinking about Java. When you do, go through Trail: Getting Started (The Java™ Tutorials)

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

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

    Default Re: Error: Could not find or load main class HelloWorld

    Quote Originally Posted by Cutejeff View Post
    i tried again and got this error

    c:\Program Files\javac>javac Greetings.java
    Greetings.java:8: error: error while writing Greetings: Greetings.class (Access
    is denied)
    public class Greetings
    ^
    1 error
    What I said. Recent Windows versions don't allow you to write files in the Program Files directory tree. Create a branch of your Documents tree for your Java apps.

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

  8. #8
    jhuber151 is offline Member
    Join Date
    Jul 2012
    Posts
    55
    Rep Power
    0

    Default Re: Error: Could not find or load main class HelloWorld

    I am going to try with your code from before
    Java Code:
    C:\Users\hp>cd desktop
     
    C:\Users\hp\Desktop>cd java
     
    C:\Users\hp\Desktop\java>cd StudentFiles
     
    C:\Users\hp\Desktop\java\StudentFiles>cd Ch02
     
    C:\Users\hp\Desktop\java\StudentFiles\Ch02>cd Hello
     
    C:\Users\hp\Desktop\java\StudentFiles\Ch02\Hello>//I AM ASSUMING THIS IS THE CLASS DIRECTORY WITH THE .JAVA FILE IN IT
    
    C:\Users\hp\Desktop\java\StudentFiles\Ch02\Hello> javac HelloWorld.java
    
    C:\Users\hp\Desktop\java\StudentFiles\Ch02\Hello> dir
    //MAKE SURE IT CREATED A .CLASS FILE
    
    C:\Users\hp\Desktop\java\StudentFiles\Ch02\Hello> java HelloWorld

  9. #9
    Cutejeff is offline Member
    Join Date
    Jul 2012
    Location
    Nigeria
    Posts
    7
    Rep Power
    0

    Default Re: Error: Could not find or load main class HelloWorld

    Microsoft Windows [Version 6.0.6002]
    Copyright (c) 2006 Microsoft Corporation. All rights reserved.

    C:\Users\hp>cd desktop

    C:\Users\hp\Desktop>cd java\StudentFiles

    C:\Users\hp\Desktop\java\StudentFiles>cd Cho2
    The system cannot find the path specified.

    C:\Users\hp\Desktop\java\StudentFiles>cd Ch02

    C:\Users\hp\Desktop\java\StudentFiles\Ch02>cd Hello

    C:\Users\hp\Desktop\java\StudentFiles\Ch02\Hello>j avac Greetings.va
    error: Class names, 'Greetings.va', are only accepted if annotation processing i
    s explicitly requested
    1 error

    C:\Users\hp\Desktop\java\StudentFiles\Ch02\Hello>
    C:\Users\hp\Desktop\java\StudentFiles\Ch02\Hello>j ava
    Usage: java [-options] class [args...]
    (to execute a class)
    or java [-options] -jar jarfile [args...]
    (to execute a jar file)
    where options include:
    -d32 use a 32-bit data model if available
    -d64 use a 64-bit data model if available
    -client to select the "client" VM
    -server to select the "server" VM
    -hotspot is a synonym for the "client" VM [deprecated]
    The default VM is client.

    -cp <class search path of directories and zip/jar files>
    -classpath <class search path of directories and zip/jar files>
    A ; separated list of directories, JAR archives,
    and ZIP archives to search for class files.
    -D<name>=<value>
    set a system property
    -verbose[:class|gc|jni]
    enable verbose output
    -version print product version and exit
    -version:<value>
    require the specified version to run
    -showversion print product version and continue
    -jre-restrict-search | -no-jre-restrict-search
    include/exclude user private JREs in the version search
    -? -help print this help message
    -X print help on non-standard options
    -ea[:<packagename>...|:<classname>]
    -enableassertions[:<packagename>...|:<classname>]
    enable assertions with specified granularity
    -da[:<packagename>...|:<classname>]
    -disableassertions[:<packagename>...|:<classname>]
    disable assertions with specified granularity
    -esa | -enablesystemassertions
    enable system assertions
    -dsa | -disablesystemassertions
    disable system assertions
    -agentlib:<libname>[=<options>]
    load native agent library <libname>, e.g. -agentlib:hprof
    see also, -agentlib:jdwp=help and -agentlib:hprof=help
    -agentpath:<pathname>[=<options>]
    load native agent library by full pathname
    -javaagent:<jarpath>[=<options>]
    load Java programming language agent, see java.lang.instrument

    -splash:<imagepath>
    show splash screen with specified image
    See Java SE Documentation at a Glance for m
    ore details.

    C:\Users\hp\Desktop\java\StudentFiles\Ch02\Hello>d ir
    Volume in drive C has no label.
    Volume Serial Number is E01E-0974

    Directory of C:\Users\hp\Desktop\java\StudentFiles\Ch02\Hello

    17/07/2012 01:45 <DIR> .
    17/07/2012 01:45 <DIR> ..
    12/10/2010 20:02 446 Greetings.java
    12/10/2010 20:00 604 Greetings2.java
    17/07/2012 06:32 186 HelloWorld.java
    3 File(s) 1,236 bytes
    2 Dir(s) 74,627,743,744 bytes free

    C:\Users\hp\Desktop\java\StudentFiles\Ch02\Hello>

    thats what i got

  10. #10
    Cutejeff is offline Member
    Join Date
    Jul 2012
    Location
    Nigeria
    Posts
    7
    Rep Power
    0

    Default Re: Error: Could not find or load main class HelloWorld

    how will i know if it has created a .class file?

  11. #11
    Cutejeff is offline Member
    Join Date
    Jul 2012
    Location
    Nigeria
    Posts
    7
    Rep Power
    0

    Default Re: Error: Could not find or load main class HelloWorld

    Hello i think i"ve got it let me try it again

  12. #12
    Cutejeff is offline Member
    Join Date
    Jul 2012
    Location
    Nigeria
    Posts
    7
    Rep Power
    0

    Default Re: Error: Could not find or load main class HelloWorld

    yes i've got it thanks to u all i really appreciate.

  13. #13
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default Re: Error: Could not find or load main class HelloWorld

    ... did your school not teach you how to use a command line? I have never taken classes, but I have taught a few and that is usually what I teach first. Maybe I am doing something wrong.

    how will i know if it has created a .class file?
    How do you know if you wrote a paper in Microsoft word and it saved as a .doc file. The answer, you check the folder you saved it in. Same with compiling. Check the folder you compiled in and there should be a file(s) with the name of the file you just compiled. Another way to know, is that javac will return without any errors. If you just get a new line in the command prompt, you will know something went really RIGHT , or REALLY, REALLY, WRONG!

    My suggestion before jumping into Java, as DarrylBurke, is to learn how to use your OS by learning how things work on your OS such as the command-line. Get so comfortable with it that you will use it for EVERYTHING. Try jumping into Linux and DO NOT INSTALL GUI. Get a good book that explains how to use the *nix command lines and learn from there. That is how I learned how to use a terminal.

    Happy Learning!!
    My API:
    Java Code:
    cat > a.out || cat > main.class

Similar Threads

  1. Error: Could not find or load main class HelloWorld
    By grejsimojs in forum New To Java
    Replies: 8
    Last Post: 07-11-2012, 10:27 PM
  2. Error: Could not find or load main class
    By Tybald in forum Eclipse
    Replies: 5
    Last Post: 05-28-2012, 11:22 AM
  3. Error: Could not find or load the main class build.jar
    By Stoyicker in forum New To Java
    Replies: 2
    Last Post: 05-24-2012, 09:58 PM
  4. Replies: 3
    Last Post: 12-09-2011, 03:51 AM
  5. Error: Could not find or load main class
    By ITSlave in forum New To Java
    Replies: 4
    Last Post: 09-15-2011, 09: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
  •