58

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

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
ThisGuy
  • 833
  • 1
  • 9
  • 19
  • Did you try cleaning and building your project?. Show us your project structure from eclipse. – TheLostMind Jun 09 '14 at 09:55
  • Put screen shot of **marks** window in your question. Because you have to consider about exclamation mark in view. – Cyclops Jun 09 '14 at 10:02
  • thank you to all who replied. It suddenly worked. I don't know how but I restarted, cleaned and created new project and created file inside src folder. Thanks! – ThisGuy Jun 09 '14 at 10:47
  • https://www.youtube.com/watch?v=hrS_uvswsnk refer this link for error resolvement . – Ritik Kamboj Apr 15 '22 at 07:47

13 Answers13

64

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
Ramraj
  • 2,040
  • 14
  • 17
16

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?

NekoKikoushi
  • 496
  • 5
  • 16
14

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.

Ninad Pingale
  • 6,801
  • 5
  • 32
  • 55
  • 1
    It helped me alot. But during the course of fixing it i faced challange of selecting main Class. Inbuilt search didn't work properly. So I entered main class location in Main.class section in Run configuration page. – Anup Prakash Oct 07 '20 at 10:19
14

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.

phil_20686
  • 4,000
  • 21
  • 38
  • If you are not in a place to change the package, try marking the current package under sources. Check: https://stackoverflow.com/a/50087008/3604656 – Ramraj Apr 29 '18 at 13:23
6

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.

Sudhir Gaurav
  • 107
  • 1
  • 4
2

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

Community
  • 1
  • 1
Cyclops
  • 649
  • 3
  • 8
  • 33
1

Create a source folder under Java Resources enter image description here

sarath
  • 767
  • 12
  • 19
1

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

0

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!

Manfred Radlwimmer
  • 13,257
  • 13
  • 53
  • 62
0

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

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Pavan Yogi
  • 180
  • 2
  • 7
0

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

-1

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.

-6

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