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.
class. that fixed my issue.
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.
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:
- backup all your .java files to some other location
- delete entire java project
- create new java project by right click on root & click new
- 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
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
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 :
- go to project properties
- go to java build path
- 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.
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
- my .java files were not linked and
- 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
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.
- Editor does not contain a main type
- Editor does not contain a main type in Eclipse
- Editor does not contain main type
- java - Editor does not contain a main type
- Android: Editor does not contain a main type
- Editor does not contain main type in Eclipse
- Eclipse Editor does not contain a main type
- Editor does not contain a main type - messed up Build path config
- Editor does not contain a main type in sample project
- Error: Selection does not contain a main type
- Java launch error selection does not contain a main type
- Editor does not contain a main type, even though it does
- Selector does not contain a main type eclipse
- Selection does not contain a main type in maven-archetype-webapp
- Eclipse | Selection does not contain a main type yet main is there
- Eclipse - Java - Selection does not contain a main type - git clone
- Trying to run corejava ManagerTest.java Error: Selection does not contain a main type in Eclipse
- generated Xpand code ' editor does not contain a main type'. However I have a main method
- Eclipse error: "Editor does not contain a main type"
- Eclipse error: 'Selection does not contain a main type/an applet'
- Eclipse saying selection does not contain a main type?
- Why do I get a "Selection does not contain a main type" message in Eclipse?
- "Selection does not contain a main Type" - Eclipse Run Error
- Not able to create executable jar for webdriver+TestNg project which does not contain main method in any class
- Imported project in Eclipse doesn't run, says - 'Editor does not contain a main type.'
- AspectJ causing "Editor does not contain a main type" error
- Eclipse error with archived java projects "editor does not contain main type"
- ERROR: Does not contain source for Thread.class - Class File Editor
- Eclipse error when trying to run Java application - "Selection does not contain a main type" - But it does?
- Why do I get the "Selection does not contain a main type" when my class has a main?
More Query from same tag
- undefined reference to `WinMain@16' collect2.exe: error: ld returned 1 exit status
- Cleaning messed up my Android project
- Drag and Drop visual editor in Eclipse
- How to inherit External Maven POM in Project POM
- Are eclipse C++ IDE Workspaces fully compatible with all IDE platform versions? (Linux, iOS, Windows...)
- Should I use question mark type argument or suppress rawtypes warning?
- How to build a Java Servlet in Eclipse?
- Splash screen & login dialog box doesn't stick together
- Getting NoClassDefFoundError only with TestCases
- Is it possible to work on multiple bug fixes using Eclipse & SVN?
- Is macbook air 501 64-bit or 32-bit? Which version of Eclipse should I choose?
- Error when viewing Google App Engine application after deployment
- USB Debugging with Samsung Galaxy SII / Eclipse
- Eclipse : Whether to select Local Or Shared File during Remote Debugging
- Creating a maven webapp generates error
- Need help setting up a (Tomcat) web app in Eclipse for debugging
- Arguments to path.resolve must be strings Use --force to continue
- Android Application gets a ClassNotFoundException
- How can I change the formatting of arrays within annotations in Eclipse?
- Setting up Weka in Eclipse for code analysis(design smells,patterns,metrics and possible improvements)
- Why Eclipse deletes a reference to the function?
- How do I fix 'Source not found' error when debugging in Eclipse, using Selenium WebDriver?
- How to use StanfordCoreNLP jar to conduct semantic analysis in a Java Map/Reduce Job?
- Zebra QLn320 Link-OS USB communications error
- Package explorer view in Eclipse
- Multiple pages in Eclipse android application
- Importing AOSP to Eclipse
- Eclipse (Juno) doesn't show all warnings
- Hello having issue with my code in android eclipse
- Eclipse set up for multiple languages