Results 1 to 17 of 17
  1. #1
    iSamir is offline Member
    Join Date
    Jun 2013
    Posts
    6
    Rep Power
    0

    Default Error: Could not find or load main class

    I just began learning Java so I could eventually get into game development.

    I wrote my "Hello World" script

    Error: Could not find or load main class-screenshot_2.png

    I compiled it correctly by doing "javac hello.java" but when I tried to run the .class file I got:

    Error: Could not find or load main class-screenshot_3.png

    I changed the classpath to the same as my Path, which is:

    C:\Program Files\Java\jdk1.7.0_25\bin

    I decided to try again but now I get these two:

    Error: Could not find or load main class-screenshot_4.png

    Can anybody help me? This has been stalling me for the past 2 days.
    Last edited by iSamir; 06-24-2013 at 12:24 AM.

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,414
    Rep Power
    5

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

    The class which has the main entry point must be declared public. And the program must be in a file of the class name with a .java suffix.

    So in your case:

    public class Dortle {
    }

    Put it in a file Dortle.java.

    Then compile and run it.

    javac Dortle.java
    java Dortle

    Since you are new to Java I recommend checking out the tutorials linked in my signature.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

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

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

    Java is case sensitive. dortle is not the same as Dortle.

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

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

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

    Quote Originally Posted by jim829 View Post
    The class which has the main entry point must be declared public. And the program must be in a file of the class name with a .java suffix.
    Nope.

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

  5. #5
    iSamir is offline Member
    Join Date
    Jun 2013
    Posts
    6
    Rep Power
    0

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

    Quote Originally Posted by jim829 View Post
    The class which has the main entry point must be declared public. And the program must be in a file of the class name with a .java suffix.

    So in your case:

    public class Dortle {
    }

    Put it in a file Dortle.java.

    Then compile and run it.

    javac Dortle.java
    java Dortle

    Since you are new to Java I recommend checking out the tutorials linked in my signature.

    Regards,
    Jim
    Thanks for your help but it didn't work, I get the same error.

    Error: Could not find or load main class-screenshot_5.png

    Error: Could not find or load main class-screenshot_6.png

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

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

    Post a directory listing.

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

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

    That's not the same error.

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

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

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

    Have you tried running with the classpath flag set?
    Java Code:
    java -cp . Dortle
    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  9. #9
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,414
    Rep Power
    5

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

    Well, you're right of course. I've always believed it; never questioned it; and have always done it. It's times like this when my confidence gets shaken.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  10. #10
    iSamir is offline Member
    Join Date
    Jun 2013
    Posts
    6
    Rep Power
    0

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

    Quote Originally Posted by DarrylBurke View Post
    Have you tried running with the classpath flag set?
    Java Code:
    java -cp . Dortle
    db
    Thank you so much, I love you(no homo).

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

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

    Now the next thing to do is to inspect the system variable CLASSPATH; if there aren't any programs that require it, remove it. Or if you wish to play it safe, append ";." for Windows or ":." for *n?x (without the quotes).

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

  12. #12
    iSamir is offline Member
    Join Date
    Jun 2013
    Posts
    6
    Rep Power
    0

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

    My CLASSPATH is solely dedicated to Java.

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

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

    Quote Originally Posted by iSamir View Post
    My CLASSPATH is solely dedicated to Java.
    What?

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

  14. #14
    iSamir is offline Member
    Join Date
    Jun 2013
    Posts
    6
    Rep Power
    0

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

    Quote Originally Posted by DarrylBurke View Post
    What?

    db
    Oops, sorry. I meant that I already removed unnecessary programs from the CLASSPATH.

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

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

    So, what is the present content of the CLASSPATH? Copy and paste it here.

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

  16. #16
    iSamir is offline Member
    Join Date
    Jun 2013
    Posts
    6
    Rep Power
    0

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

    C:\Program Files\Java\jdk1.7.0_25\bin

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

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

    You don't need that. Examine the contents of that folder: there are no class files there. If that's all of it, you can (and should) delete the CLASSPATH variable.

    Somewhere along, you've confused what should be in the PATH and what in the CLASSPATH.

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

Similar Threads

  1. Error:Could Not Find or Load Main Class
    By vickyv200 in forum New To Java
    Replies: 3
    Last Post: 08-29-2012, 01:10 AM
  2. Error: could not find or load main class
    By sloppygecko in forum New To Java
    Replies: 3
    Last Post: 08-08-2012, 03:11 PM
  3. Error: Could not find or load main class
    By Tybald in forum Eclipse
    Replies: 5
    Last Post: 05-28-2012, 11:22 AM
  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
  •