Thursday, January 21, 2016

Error: Could not find or load main class in Java

Following are some of the major causes of this error.

1. Misspell the class name. For example you want to execute command "java HelloWorld", but did "java HaloWorld".

2. Use <class name>.class or <class name>.java. For example use command "java HelloWorld.class" or "java HelloWorld.java" instead of "java HelloWorld".

3. The class path is not set for the class you execute. You may fix this by doing one of the followings.           A. Add class path to the CLASSPATH environment  variable and make sure it is correct.

          B. Use the -cp or -classpath option when execute the class.
                 For example, java -cp C:\Test MyTest

4. The jars required for executing your class are not set in your CLASSPTH,

5. When the class is in a package, it is not executed in the right directory or with the correct complete name.
          For example, the CareMaster class is created in the com.care.gui package.

          A. You must execute it using its complete name,

                java com.care.gui.CareMaster

                if you use "java CareMaster", it will cause the "Could not find or load main class CareMaster" error.

         B. You must execute the class in the directory containing the com directory.
     
6. Execute a jar that does not have a Manifest.mf file or the Main-Class and/or the Class-Path in the manifest.mf are not correctly set.

If none of the above works, try to close all your IDEs and applications, wait for a few minutes and retry. Or turn off your computer, let it rest for a few minutes.

---------------------------------------------------------------------------------------------------

                        


If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

References

1. Run .jar file in Windows
2. How to add jars to the class path of your main application when you are doing a distribution/software release



No comments:

Post a Comment