Could not find or load main class ... {Error}

Soufiane Rafik
2 min readJan 29, 2018

PS: My articles are for beginners who don’t know much about programming, I’m trying to explain things as simple as I can without using a lot of technical words.

There is nothing frustrating than when your program runs perfectly in your IDE but it crashes once you run it on a terminal or a different platform altogether.

I had to submit a little project for my Data Structures class, my program ran perfectly on Netbeans but failed to run on the Terminal with the error message: Could not find or load main class ...

This is a common problem that new Java developers experience.

When you create a project on Netbeans, you will see that Netbeans create a new package with the project’s name and put your class inside it.

Java class inside a package in the Source Packages file.
Package of the class

And if you copy your “.Java” file in another folder or Machine and try to run it from the terminal, you will get this error:

Error Message: Could not find or load main class ...

The solution is very simple; you just need to remove the package call.

package rgbcolorarray;

Delete: package rgbcolorarray;
Unlisted

--

--