. Advertisement .
..3..
. Advertisement .
..4..
Hello everyone. I am having a problem with ”error: could not find or load main class java” and I want to ask for your help. While I am running this program:
package com.baeldung;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello world..!!!");
}
}
I get this error:
$ java HelloWorld
Error: Could not find or load main class java
I don’t know the why this error appears and what is the best solution for it? Does anyone have suggestions for me? Please write below. Thanks a lot!
The cause:
The name HelloWorld you are using is not a qualified name, its fully qualified name is
com.baeldung.HelloWorld
. If you want to run a Java class that is a part of package, you must provide fully qualified name for it.Solution:
First, you need to run your program from the
com/baeldung
directory:When you use the fully qualified class name
com.baeldung.HelloWorld
, Java looks for theHelloWorld.class
file in thecom/baeldung
directory, it will be under the directory where you are running the program.If you are already inside
com/baeldung
, Java still cannot find and run theHelloWorld
program, you will needd to move back to the parent folder and run this command:As you see, the error will disappear by this way.