Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

What does “Could not find or load main class” mean?

A typical issue that new Java developers experience is that their programs fail to run with the blunder message: Could not discover or load main class ...

What's the significance here, what causes it, and how could you fix it?
by

2 Answers

espadacoder11
If your source code name is HelloWorld.java, your compiled code will be HelloWorld.class.

You will get that error if you call it using:

java HelloWorld.class

Instead, use this:

java HelloWorld
sandhya6gczb
The normal syntax to launch the java program is

java [ <options> ] <class-name> [<arg> ...]

where <option> is a command line option (starting with a "-" character), <class-name> is a fully qualified Java class name, and <arg> is an arbitrary command line argument that gets passed to your application.

When you get the message "Could not find or load main class ...", that means that the first step has failed. The java command was not able to find the class. And indeed, the "..." in the message will be the fully qualified class name that java is looking for.

Reasons for such error can be
1 you made a mistake with the class name argument
2. the application's classpath is incorrectly specified
3. the wrong directory is on the classpath
4. the subdirectory path doesn't match the FQN
5. dependencies missing from the classpath.
6. the class has been declared in the wrong package

Login / Signup to Answer the Question.