Accepted answer

i have this problem a lot with eclipse and scala. it helps if you clean your workspace and rebuild your project.

sometimes eclipse doesn't recognize correctly which files it has to recompile :(

edit: the code runs fine in eclipse


you need locate file .java in folder src (in project explorer of eclipse) and then it run. i have just add a file .java into project and it isn't in folder src, so i have a same error. i put again it into src, then it was build.


instead of adding file, add class. file->new->class. that fixed my issue.


add a main method method inside the class to overcome this problem. i was facing the same issue regarding including the main method inside my code i resolved my problem.


for me, in eclipse 3.6, this problem occurs when my main method is not public. i caused the problem by having a main method like this:

static void main(string[] args) 

the dubugger was unable to detect this by itself. i am pretty suprised eclipse overlooked this.


follow the below steps:

  1. backup all your .java files to some other location
  2. delete entire java project
  3. create new java project by right click on root & click new
  4. restore all the files to new location !!


in the worst case - create the project once again with all the imports from the beginning. in my case none of the other options worked. this type of error hints that there is an error in the project settings. i once managed to solve it, but once further developments were done, the error came back. recreating everything from the beginning helped me understand and optimize some links, and now i am confident it works correctly.


file >> import >> existing projects into workspace >> select archive filed >> browse and locate file >> finish. if its already imported some other way delete it and try it that way. i was having the same problem until i tried that.


one more thing to check: make sure that your source file contains the correct package declaration corresponding to the subdirectory it's in. the error mentioned by the op can be seen when trying to run a "main type" declared in a file in a subdirectory but missing the package statement.


i have this problem too after i changed the source folder. the solution that worked for is just editing the file and save it.


try 'update project'. once i did this, the run as java application option appeared.


in my particular 'hello world' case the cause for this problem was the fact, that my main() method was inside the scala class.

i put the main() method under the scala object and the error disappeared.

that is because scala object in java terms is the entity with only static members and methods inside.

that is why java's public static void main() in scala must be placed under object.

(scala class may not contain static's inside)


on reason for an error of: "editor does not contain a main type"

error encountered in: eclipse neon

operating system: windows 10 pro

when you copy your source folders over from a thumb-drive and leave out the eclipse_projects.metadata folder.

other than a fresh install, you will have to make sure you merge the files from (thrumb-drive)f:eclipse_projects.metadata.plugins .

these plug-ins are the bits and pieces of library code taken from the sdk when a class is created. i really all depends on what you-----import javax.swing.*;----- into your file. because your transferring it over make sure to merge the ------eclipse_projects.metadata.plugins------ manually with a simple copy and paste, while accepting the skip feature for already present plugins in your folder.

for windows 10: you can find your working folders following a similar pattern of file hierarchy.

c:users>mikes laptop> workspace > .metadata > .plugins <---merge plugins here


i had this problem with a java project that i imported from the file system (under eclipse helios). here's a hint: the src code didn't seem to be compiled at all, as no "bin" directory showed up.

i had to create a java project from scratch (using the wizard), then compare the .project files of the non-working and working projects.

the project giving "editor does not contain a main type" had this as the "buildspec" in the .project file:


but the working project had this as the "buildspec":


i copied this in, and the imported project worked.

i know my answer is for java, but the same might be the issue for your scala project.


may be the file you have created is outside the src(source) folder. trying to call the class object(from the file located in the src folder) from the .java file outside the source folder results in the same error. copy .java file to the source folder, then build it. the error will be gone.


i had the same problem. i had the main class out of the src package, in other folder. i move it in and correct folder and solved


run "eclipse -clean -refresh" from command line. this fixed the issue for me when all other solutions failed.


this could be the issue with the java build path. try below steps :

  1. go to project properties
  2. go to java build path
  3. go to source tab and add project's src folder

this should resolve the issue.


if it is maven project please check the java file is created under src/main/java

if you are not getting please change the jre path and create the java files in above folder structure


i just had this problem too. the solution is to make sure eclipse created the project as java project. just create a new java project and copy your class into the src folder (and import the eventual dependencies). this should fix the problem.


the correct answer is: the scala library needs to before the jre library in the buildpath.

go to java buildpath > order and export and move scala library to the top


that code is valid. have you tried to compile it by hand using scalac? also, have you called your file "addressbook", all lowercase, like the name of the object?

also, i found that eclipse, for some reason, set the main class to be ".addressbook" instead of "addressbook".


you should create your file by

selecting on right side you will find your file name,

under that will find src folder their you right click select -->class option

their your file should be created


make sure that your .java file is present either in the str package, or in some other package. if the java file with the main function is outside all packages, this error is thrown.


have faced the similar issue, resolved this by right clicking on the main method in the outline view and run as java application.


what you should do is, create a java project, but make sure you put this file in the package file of that project, otherwise you'll encounter same error.

enter image description here


a quick solution:

first, exclude the package: right click on the source package >> build path >> exclude

then include it back: right click on the source package >> build path >> include


just close and reopen your project in eclipse. sometime there are linkage problems. this solved my problem


i had the same problem. i tried all sorts of things. and i came to know that

  1. my .java files were not linked and
  2. they were not placed in the 'src' folder.

things i did:

project properties >> java build path >> source

  • deleted the original 'src' folder which was empty using 'remove' option
  • added the source that contained my source .java files using the 'add folder' option

this solved the error.


you can try to run the main function from the outline side bar of eclipse.



just make sure that the folder you work in is added to the built path:

right-click your folder --> build path --> use as source folder

and it should now find main therein.


you have to make sure that your .java files are in the .src folder in eclipse. i had the same exact problem until i got it figured out.


a simpler way is to close the project and reopen it.


in eclipse, make sure you add your source folder in the project properties -> java build path -> source. otherwise, the main() function may not be included in your project.

Related Query

More Query from same tag