This problem, in most cases, is not caused by error in your codes, it’s more likely a mistake of misplaced Java files. I encountered this problem when I run a Java file using Eclipse for the first time. Previously I was using jCreator to do my Java programming, so I am not used to project-based IDE like Eclipse.
First thing to do is of course to check whether your java file DOES really has no main() method to be run. Check the syntax too. If you are sure about your syntax, proceed to next step.
The syntax:
public static void main (String[] args) {
}
Go to Project > Properties > Java Build Path > Source tab
In most cases, your source folder will be workspace-folder/project-name/src. So, when Eclipse run your Java file, it will look into this folder. So all your Java files should be in this folder!
Now check out your Project Tree. Example below shows my project tree, with 2 Java file.
And this is where i found my problem. My Java files were not placed inside “src” folder so Eclipse is complaining. So drag them into the “src” folder. Eclipse should now stop complaining about the problem.
Thank you. In Eclipse I had copied some old files into a new project, but until I read your explanation, I had not realized that I had not copied the .java files INTO the src folder. They were under it, but not in it.
Thanks for a very clear explanation of what I was doing wrong.
But still i am getting the same error. Can u pls help me to fix this error.
That worked for me. It was driving me buts because I copied a small program that worked in order to play around with some changes.
Ye effings gods, I have NO problem with hideously complex programs but I freaking HATE bureocracy. Why in the effing ell con’t someone design an environment with simple to understand bureocracy? Why the effing ell would someone create an environment so that when you created a project from scratch you would have to change file locations manually.
Effing ell.
I am in tears of joy. Nowhere could I find the solution. Thousands of shit posts on forums and no joy. Thank you so much. I love you.
Great! Step 2 rly worked 4 me. Thanks!