How to Fix “Editor does not contain a main type” Error in Eclipse

Posted in Misc. on 9 August 2011 5 comments

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.

#1 – Syntax of main() Method

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) { 
 
}

#2 – Check your project source folder / build path

Go to Project > Properties > Java Build Path > Source tab

eclipse project source, java build path

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.

eclipse drag into src folder

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.


There were a lot of forum topics regarding this problem so I decided to post a topic on this. I have to admit that I am quite silly to did this mistake. Anyway, cheers!

 

Posted by Zen on 9 August 2011 • 37,658 visits 5 comments
Tags : ,


or Subscribe to specific category only :




  - 5 Comments


Bob Wengert says:

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.

sharavathi says:

But still i am getting the same error. Can u pls help me to fix this error.

fred says:

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.

Gary says:

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.

Kuba says:

Great! Step 2 rly worked 4 me. Thanks!

Leave a Reply

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

Previous Post
«
Next Post
»