Results 1 to 9 of 9
  1. #1
    grejsimojs is offline Member
    Join Date
    Jul 2012
    Posts
    3
    Rep Power
    0

    Default Error: Could not find or load main class HelloWorld

    Hi,
    So I've started coding Java and I'm using Notepad++ to code and compile.

    1. I installed a plugin to Notepad++ called "NppExec"
    2. When I press F6, I get a console
    3. In the console I was told to type in the following code:

    javac "$(FULL_CURRENT_PATH)" java -classpath "$(CURRENT_DIRECTORY)" "$(NAME_PART)"

    1. So I did, and in the console, I get exactly this following error:

    javac "C:\Program Files\Notepad++\HelloWorld.java" CreateProcess() failed with error code 2: The system cannot find the file specified.
    java -classpath "C:\Program Files\Notepad++" "HelloWorld" Process started >>> Error: Could not find or load main class HelloWorld <<< Process finished. ================ READY ================
    So the main error, I believe, is "Error: Could not find or load main class HelloWorld"
    But what have I done wrong?
    Here's my simple code:
    import java.applet.; import java.awt.;
    public class HelloWorld extends Applet { public void paint (Graphics g) { g.drawString("Hello World!", 50, 25); } }
    And the file name is called HelloWorld.java
    Thanks guys

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,185
    Rep Power
    20

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

    Where is your HelloWorld.java file?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    grejsimojs is offline Member
    Join Date
    Jul 2012
    Posts
    3
    Rep Power
    0

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

    It's in C:\Program Files\Notepad++

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,185
    Rep Power
    20

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

    Not according to the error thrown by javac.
    Ah, unless it's javac it can't find.

    Anyway something on that line is not working, which is why the 'java...' part isn't working as HelloWorld has not been compiled.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    grejsimojs is offline Member
    Join Date
    Jul 2012
    Posts
    3
    Rep Power
    0

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

    Yes I know. But it SHOULD work, shouldn't it? It's in the correct directory and all. I don't see why it doesn't work.

    The NPPExec should compile the java file. Do you know how to solve this sort of issue?

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,185
    Rep Power
    20

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

    Try and run javac "C:\Program Files\Notepad++\HelloWorld.java" from the command line.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    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

    Well, I have two suggestions for you on compiling this program.
    The first would be to remove the classpath arguments from your command and see if you can compile the program.
    Second, if it does not work even then, then go into your terminal (shell, command-prompt whatever you call yours) and see if you can compile the program from there. Using nothing but
    Java Code:
     javac HelloWorld.java
    whilst in the same directory.

    Next up! Do not use java to run this. Might sound strange, but you are making an Applet. Applets are viewed and run via the web based plugin or using the JDK's Appletviewer program. You still need to write up an HTML file with the applet embedded in order to get appletviewer to work. The Java Applet Viewer should help.

    Lastly, you messed up on your imports. you need an '*' after the periods. This tells the compile to include everything in that folder/classpath. EX:
    Java Code:
    import javax.swing.;
    is wrong because you did not specify what class you want after the swing. You can either define a name of the specific class you want or use
    Java Code:
    import javax.swing.*;
    to get all of them.

    Oh! and one last tip about applets. I am not 100% sure about this, but from what I read, it is highly recommended that you have a
    Java Code:
     public void init()
    in your applet to tell the JVM plugin that you applet is starting somewhere. That line of code and the code within that function should be treated the same as
    Java Code:
     public static void main()
    because they are both the starting points of the program.

    Hope this helps!
    My API:
    Java Code:
    cat > a.out || cat > main.class

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

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

    I didn't even notice there was code there in the OP...
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #9
    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

    Quote Originally Posted by Tolls View Post
    I didn't even notice there was code there in the OP...
    yeah, I know. it was hard to see without the [code] marks. Start using those!
    My API:
    Java Code:
    cat > a.out || cat > main.class

Similar Threads

  1. Error: Could not find or load main class
    By Tybald in forum Eclipse
    Replies: 5
    Last Post: 05-28-2012, 12:22 PM
  2. Replies: 29
    Last Post: 02-02-2012, 09:23 PM
  3. Replies: 3
    Last Post: 12-09-2011, 04:51 AM
  4. Error: Could not find or load main class Ops.java
    By Javasubbu in forum New To Java
    Replies: 4
    Last Post: 10-05-2011, 11:52 PM
  5. Error: Could not find or load main class
    By ITSlave in forum New To Java
    Replies: 4
    Last Post: 09-15-2011, 10: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
  •