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:
13 Answers
Problem is that your folder is not identified as a Source folder.
- Right click on the project folder -> Properties
- Choose 'Java Build Path'
- Click on 'Sources' tab on top
- Click on 'Add Folder' on the right panel
- Select your folders and apply
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?
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.
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.
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
Create a source folder under Java Resources
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/"/> fixed the issue
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!
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
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
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.
Just change "String[] args" to "String args[]".