edit: Nope. I've found your code in the other thread (here) and your main method, which can access the private Main() constructor, so my guess was wrong.
The visibility of the class doesn't (and shouldn't) matter. It's the visibility of the entry point (Main.main).
But that's not even the error, whether it's public or not, it says it can't find the class (with the same details).
So the problem is probably some wrong setting in Eclipse or a different directory structure than what Eclipse expects. My directory structure in the shell snippet is plain java with a directory for each part of the package name (separated by a dot). Java's classpath needs to be set to the current directory, so that it can find the Main class (-cp .). But your Eclipse project has at least an additional src directory as entry point. When I start new java projects I use maven or gradle and follow their directory structure, which also have your srcdirectory, but additionally a main and a java directory. Then I can use any Java IDE, because they all support maven's directory structure.
P.S.: Actually you don't need -cp, yet, as long as you've got a single .java file only.
I guess the Main() constructor has to be
public
.edit: Nope. I've found your code in the other thread (here) and your main method, which can access the private Main() constructor, so my guess was wrong.
Tried it. It doesn't work.
The visibility of the class doesn't (and shouldn't) matter. It's the visibility of the entry point (
Main.main
).But that's not even the error, whether it's public or not, it says it can't find the class (with the same details).
In such a case I try to run things from the command line. And it works:
So the problem is probably some wrong setting in Eclipse or a different directory structure than what Eclipse expects. My directory structure in the shell snippet is plain java with a directory for each part of the package name (separated by a dot). Java's classpath needs to be set to the current directory, so that it can find the Main class (
-cp .
). But your Eclipse project has at least an additionalsrc
directory as entry point. When I start new java projects I use maven or gradle and follow their directory structure, which also have yoursrc
directory, but additionally amain
and ajava
directory. Then I can use any Java IDE, because they all support maven's directory structure.P.S.: Actually you don't need
-cp
, yet, as long as you've got a single.java
file only.On second thought, what exactly causes the main class not to be found.
One may be mistyping main, or not providing a main class entry.
But what things can cause this error, and what can I do to resolve it (within my Eclipse project)?