[java] Editor does not contain a main type in Eclipse

I downloaded eclipse-jee-kepler-SR1-linux-gtk-x86_64.tar.gz. This eclipse is built-in with java and my Lubuntu is 64-bit. Whenever I compile and run a simple code in java like this one below:

public class Sample{

   public static void main(String[] args){
       System.out.println("YOLO");
   }
}

I always get an Editor does not contain a main type. I put the file in a project folder called Sample. This eclipse should compile java code because its an IDE distribution specialized for java.

How can i resolve this error?

Any help would be much appreciated.

Here's my project structure: enter image description here

This question is related to java eclipse

The answer is


Make sure you do Run As > Java Application.

If not you could try a Project > Clean

Some more questions that deals with this that could be helpful, Refer this


Right click your project > Run As > Run Configuration... > Java Application (in left side panel) - double click on it. That will create new configuration. click on search button under Main Class section and select your main class from it.


First look for the main method is there or not.If it is there, do restart your eclipse and right click on the page which having main method, Go to run as Java application.


Right click on your project, select New -> Source Folder

Enter src as Folder name, then click finish.

Eclipse will then recognize the src folder as containing Java code, and you should be able to set up a run configuration


Problem is that your folder is not identified as a Source folder.

  1. Right click on the project folder -> Properties
  2. Choose 'Java Build Path'
  3. Click on 'Sources' tab on top
  4. Click on 'Add Folder' on the right panel
  5. Select your folders and apply

Just change "String[] args" to "String args[]".


I suspect the problem is that Sample.java should be in a package inside the src folder.

I guess that eclipse will not automatically look outside of there.


place your main method class in src folder(in Eclipse Environment).


Right click on Sample.java file and delete it. Now go to File -> New -> Class , enter name of program (i.e. hello) , click on finish . It will create file hello.java. Enter source code of program and finallly press ctrl + F11

click here to see screenshot1

click here to see screenshot2


I just had this exact same problem. This will sound crazy but if someone sees this try this before drastic measures. delete method signature:

public static void main(String args[])

(Not the body of your main just method declaration)

Save your project then re-write the method's header back onto its respective body. Save again and re-run. That worked for me but if it doesn't work try again but clean project right before re-running.

I don't know how this fixed it but it did. Worth a shot before recreating your whole project right?


Create a source folder under Java Resources enter image description here


I had the same issue. I had accidentally deleted the .classpath and .project file in my workspace. Luckily it was in Recycle bin, as soon as it was restored, there were no issues.


Ideally, the source code file should go within the src/default package even if you haven't provided any package name. For some reason, the source file might be outside src folder. Create within the scr folder it will work!


For me, classpath entry in .classpath file isn't pointing to the right location. After modifying it to <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> fixed the issue


I installed Eclipse and created a Java project. Created new Java file outside the 'src' directory and tried to run that. I got the same error "Editor does not contain a main type". I just moved the java file into the 'src' folder and could simply run the program. I couldn't understand what other answers were asking to try. It was so simple.