I am running a simple "HelloWorld" Program. I get this error in the command prompt:
Could not find or load main class
HelloWorld
.
I have set the CLASSPATH
and PATH
variable in the system. In the cmd
prompt, I am running from the directory where I have saved HelloWorld
program. I can see the class name and the file name are same and also .class
file created in the same directory. What else could be the problem?
My sample program looks like this:
package org.tij.exercises; public class HelloWorld { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Hello World!!"); } }
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.
Sometimes due to out of memory space error, NetBeans is unable to load or find the main class. RightClick on the project node and go to Set configuration. Select the main class for your application. Then clean and build.
There are two ways to do it: Reinstall the new JRE. It should then fix the file association in the OS. Fix the file association manually.
When the Main class is inside a package then you need to run it as follows :
java <packageName>.<MainClassName>
In your case you should run the program as follows :
java org.tij.exercises.HelloWorld
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With