#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    11
    Rep Power
    0

    Error: Could not find or load main class


    hi!!!!
    When I try to run java class from command line "java Hello.class" I get this error

    Error: Could not find or load main class

    What is this?

    package hello;

    /**
    *
    * @author Lazar
    */
    public class Hello {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
    System.out.println("hello");
    // TODO code application logic here
    }
    }
  2. #2
  3. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Feb 2004
    Location
    Mobile, Alabama
    Posts
    4,023
    Rep Power
    1285
    Do you have this file in a directory called hello? When you run it at the command line, you need to make sure that the directory containing hello is in your CLASSPATH, and then use the command java hello.Hello
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    11
    Rep Power
    0
    C:\Users\Lazar\Documents\NetBeansProjects\hello\src\hello\Hello.class

    This is directory. What I have to set for the classpath and what is than command for running this program?
  6. #4
  7. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Feb 2004
    Location
    Mobile, Alabama
    Posts
    4,023
    Rep Power
    1285
    Originally Posted by lijepdan
    C:\Users\Lazar\Documents\NetBeansProjects\hello\src\hello\Hello.class

    This is directory. What I have to set for the classpath and what is than command for running this program?
    If you are at the command line inside the directory hello, then you could type

    javac -cp .. Hello.java

    java -cp .. hello.Hello
  8. #5
  9. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,733
    Rep Power
    1959
    To start the program, you only have to add the file/class name: java Hello

    [EDIT] Haven't taken the package name into path/paramater.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    11
    Rep Power
    0
    can I type just
    java hello.Hello
    without "-cp"
  12. #7
  13. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Feb 2004
    Location
    Mobile, Alabama
    Posts
    4,023
    Rep Power
    1285
    Originally Posted by lijepdan
    can I type just
    java hello.Hello
    without "-cp"
    You can if you are in the directory containing hello and if you have a CLASSPATH, the indication for the current directory . is in it.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    11
    Rep Power
    0
    It's working, thanks
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    11
    Rep Power
    0
    I finished my FTP Client application!!!!!!!!

IMN logo majestic logo threadwatch logo seochat tools logo