Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

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

like image 299
ThisGuy Avatar asked Jun 09 '14 09:06

ThisGuy


People also ask

What is main type?

MainType is a powerful but easy to use font manager and font viewer for Windows, that takes the frustration out of managing your fonts. It is packed with tons of intuitive features that makes it simple to find, preview, organize, install, and print your fonts.

How do I change the editor in Eclipse?

You can set which Eclipse editor or external program to use to open a specific type of file based on its file extension. Just select Window→ Preferences→ Workbench→ File Associations, select the file type, and associate an editor or program with it (if nothing else, you can use Eclipse's default text editor).


2 Answers

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
like image 83
Ramraj Avatar answered Oct 08 '22 20:10

Ramraj


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?

like image 35
NekoKikoushi Avatar answered Oct 08 '22 20:10

NekoKikoushi