score:38

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

score:-1

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.

score:-1

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

score:-1

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

score:0

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.

score:0

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 !!

score:0

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.

score:0

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.

score:0

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.

score:0

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

score:0

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

score:0

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)

score:0

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

score:1

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:

<buildspec>
</buildspec>

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

<buildspec>
    <buildcommand>
        <name>org.eclipse.jdt.core.javabuilder</name>
        <arguments>
        </arguments>
    </buildcommand>
</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.

score:1

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.

score:1

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

score:1

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

score:1

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.

score:1

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

score:2

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.

score:2

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

score:3

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".

score:3

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

score:3

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.

score:3

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

score:4

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

score:4

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

score:6

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

score:7

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.

score:7

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

solution

score:23

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.

score:28

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.

score:31

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

score:90

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