Page 1 of 2 12 LastLast
Results 1 to 20 of 24
Like Tree1Likes

Thread: "Error: Could not find or load main class HelloWorld" Notepad++ help please

  1. #1
    groove1 is offline Member
    Join Date
    Dec 2014
    Posts
    10
    Rep Power
    0

    Default "Error: Could not find or load main class HelloWorld" Notepad++ help please

    Hi, I'm new to this java stuff and when I go to notepad++ and this keeps coming up when I try to compile it: "Error: Could not find or load main class HelloWorld" and I really have no idea what it means...

    Thanks for your help!

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: "Error: Could not find or load main class HelloWorld" Notepad++ help please

    You say you are trying to compile it but that error is from trying to run it. So how are you compiling it?

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    groove1 is offline Member
    Join Date
    Dec 2014
    Posts
    10
    Rep Power
    0

    Default Re: "Error: Could not find or load main class HelloWorld" Notepad++ help please

    Quote Originally Posted by jim829 View Post
    You say you are trying to compile it but that error is from trying to run it. So how are you compiling it?

    Regards,
    Jim
    Ermm, I pressed F6 and typed "cd :\" then OK afterwards I typed in the location of that java file with "cd Java projects" and after that I typed in on one go "javac HelloWorld.java" and "Java HelloWorld". Is that all right? sorry for being a bit stupid but I'm a bit new :P

    Thanks, Derek

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: "Error: Could not find or load main class HelloWorld" Notepad++ help please

    Javac is used to compile the program and java is used to run it. So far so good. So can you post the code? You need a static main entry point to run the program. Please place the code between [code][/code] tags to preserve formatting.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    groove1 is offline Member
    Join Date
    Dec 2014
    Posts
    10
    Rep Power
    0

    Default Re: "Error: Could not find or load main class HelloWorld" Notepad++ help please

    Quote Originally Posted by jim829 View Post
    Javac is used to compile the program and java is used to run it. So far so good. So can you post the code? You need a static main entry point to run the program. Please place the code between [code][/code] tags to preserve formatting.

    Regards,
    Jim
    Java Code:
    class HelloWorld
    {
    public static void man(tring args[])
    {
    
    System.out.println("Hello from notepad++ program");
    
    }
    
    }
    I was watching a video on it and this is exactly what the guy typed so I'm a bit clueless, sorry

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: "Error: Could not find or load main class HelloWorld" Notepad++ help please

    You second line should be:

    public static void main(String [] args)

    You have man and tring.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  7. #7
    groove1 is offline Member
    Join Date
    Dec 2014
    Posts
    10
    Rep Power
    0

    Default Re: "Error: Could not find or load main class HelloWorld" Notepad++ help please

    Quote Originally Posted by jim829 View Post
    You second line should be:

    public static void main(String [] args)

    You have man and tring.

    Regards,
    Jim
    Sorry I'm still getting the same error. I'll show you the errors in the console:

    "Error: Could not find or load main class HelloWorld" Notepad++ help please-java-problems.png

    Thanks for your help

  8. #8
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: "Error: Could not find or load main class HelloWorld" Notepad++ help please

    The error in the editor shows it. You didn't compile the program because the javac command is running from a different directory. You need to
    be in the same directory as the file. In what directory is your java program?

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  9. #9
    groove1 is offline Member
    Join Date
    Dec 2014
    Posts
    10
    Rep Power
    0

    Default Re: "Error: Could not find or load main class HelloWorld" Notepad++ help please

    Quote Originally Posted by jim829 View Post
    The error in the editor shows it. You didn't compile the program because the javac command is running from a different directory. You need to
    be in the same directory as the file. In what directory is your java program?

    Regards,
    Jim
    Sorry I had a quick google on directories and don't understand what you're meaning... sorry, but what are they?

    Thanks

  10. #10
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: "Error: Could not find or load main class HelloWorld" Notepad++ help please

    Think folder.

    e.g. C:/user/foo user is a directory. And foo is a directory under user.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: "Error: Could not find or load main class HelloWorld" Notepad++ help please

    groove1 is in the right directory, according to that screenshot.
    The problem is that Java is case sensitive.
    The file is called 'helloworld.java', but the command uses 'HelloWorld.java'.
    The latter is the correct name for the file, because the file name should match the class name, and the class name is HelloWorld.

    So use 'Save As' under the file menu to save that file as HelloWorld.java.
    Also, I notice that the file itself is flagged as having an unsaved change. You ought to get in the habit of saving the file before compiling it, otherwise it will compile the pre-edited version.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  12. #12
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: "Error: Could not find or load main class HelloWorld" Notepad++ help please

    Good eyes! Even after you gave the answer it took me a while to figure out how you knew case was an issue.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  13. #13
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: "Error: Could not find or load main class HelloWorld" Notepad++ help please

    Quote Originally Posted by jim829 View Post
    Good eyes! Even after you gave the answer it took me a while to figure out how you knew case was an issue.
    You're not alone, I must have read over it at least a dozen times.

    This is a poster example of why using videos to learn programming is just as horrible a learning path as you can make it. For the same reason we stare at a picture and are just blind to the truth. You are distracted by too many trivial other things. I didn't even LOOK at the tab with the file name.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  14. #14
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: "Error: Could not find or load main class HelloWorld" Notepad++ help please

    Quote Originally Posted by jim829 View Post
    Good eyes!
    Ha!
    It's not often that gets said about me!

    I only noticed the tab name as I've been doing a lot of SQL and DDL fixes this past week in Notepad++ and I've got used to checking I'm updating the correct filename...
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  15. #15
    groove1 is offline Member
    Join Date
    Dec 2014
    Posts
    10
    Rep Power
    0

    Default Re: "Error: Could not find or load main class HelloWorld" Notepad++ help please

    Sorry for the late reply, I went to sleep last night and was in school all today. But after doing everything said, it still says:

    "javac HelloWorld.java
    CreateProcess() failed with error code 2:
    The system cannot find the file specified."

    I'm really having no clue why it's doing that... sorry

    "Error: Could not find or load main class HelloWorld" Notepad++ help please-java-thread.png

    Can someone check this to see if I got it right? not entirely sure on this new Java stuff...

    Quote Originally Posted by gimbal2 View Post
    You're not alone, I must have read over it at least a dozen times.

    This is a poster example of why using videos to learn programming is just as horrible a learning path as you can make it. For the same reason we stare at a picture and are just blind to the truth. You are distracted by too many trivial other things. I didn't even LOOK at the tab with the file name.
    Yeah I learnt that the hard way for python and tried doing so and just gave up due to to unintuitive learning style, this time for Java I have opted for a book called "Head First Java" :). The video was used to see if my compiler and text editor was working correctly but apparently not...
    Last edited by groove1; 12-11-2014 at 11:02 PM.

  16. #16
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: "Error: Could not find or load main class HelloWorld" Notepad++ help please

    Try this. Get out of notepad. Go to a console window. Change to the directory that contains the file and try to compile and run it. Report any errors.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  17. #17
    groove1 is offline Member
    Join Date
    Dec 2014
    Posts
    10
    Rep Power
    0

    Default Re: "Error: Could not find or load main class HelloWorld" Notepad++ help please

    Quote Originally Posted by jim829 View Post
    Try this. Get out of notepad. Go to a console window. Change to the directory that contains the file and try to compile and run it. Report any errors.

    Regards,
    Jim
    Am I doing it right? Sorry to be an nuisance...

    "Error: Could not find or load main class HelloWorld" Notepad++ help please-cmd.png

  18. #18
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: "Error: Could not find or load main class HelloWorld" Notepad++ help please

    Ugh. Your path environment variable does not know where to find the compiler and probably the jre. You could change that but I don't want to complicate matters for you. I suggest you stick with notepad and try and find out why it can't find the HelloWorld.java file. In the notepad console can you list the contents of your current directory? Is the file there?

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  19. #19
    groove1 is offline Member
    Join Date
    Dec 2014
    Posts
    10
    Rep Power
    0

    Default Re: "Error: Could not find or load main class HelloWorld" Notepad++ help please

    Quote Originally Posted by jim829 View Post
    Ugh. Your path environment variable does not know where to find the compiler and probably the jre. You could change that but I don't want to complicate matters for you. I suggest you stick with notepad and try and find out why it can't find the HelloWorld.java file. In the notepad console can you list the contents of your current directory? Is the file there?

    Regards,
    Jim
    Is the file type correct?

    "Error: Could not find or load main class HelloWorld" Notepad++ help please-java-projects.png

  20. #20
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: "Error: Could not find or load main class HelloWorld" Notepad++ help please

    Try to change the OS's settings for the file explorer to show the extensions for files. Programmers need to see the full filename with extension to be able to do their work.
    The image in your post does not show the file's extension.
    If you don't understand my response, don't ignore it, ask a question.

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 26
    Last Post: 08-01-2014, 04:56 PM
  2. Replies: 5
    Last Post: 06-12-2014, 04:12 AM
  3. Error: Could not find or load main class HelloWorld
    By philodriscoll in forum New To Java
    Replies: 7
    Last Post: 10-10-2012, 04:44 PM
  4. Error: Could not find or load main class HelloWorld
    By Cutejeff in forum New To Java
    Replies: 12
    Last Post: 07-19-2012, 08:14 AM
  5. Error: Could not find or load main class HelloWorld
    By grejsimojs in forum New To Java
    Replies: 8
    Last Post: 07-11-2012, 11:27 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
  •