The editor does not contain the main type

A simple example of Scala code on the Scala website, but when I tried to run it, I met an annoying error.

Here is the code: http://www.scala-lang.org/node/45 . When I started on Eclipse, I received this message: "The editor does not contain the main type", which prevents it from starting.

Is there anything I need to do ... ie split this file into multiple files or what?

+83
eclipse scala
Jul 11 '09 at 13:32
source share
32 answers
  • one
  • 2

I have this problem a lot with Eclipse and Scala. It helps if you clean your workspace and rebuild your project.

Sometimes Eclipse does not recognize which files it should recompile :(

Edit: Code works fine in Eclipse

+34
Jul 11 '09 at 15:04
source share

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

+78
Mar 28 2018-11-11T00:
source share

You need to make sure your .java files are in the .src folder in eclipse. I had the same problem until I understood.

+24
Feb 29 2018-12-12T00:
source share

An easier way is to close the project and reopen it!

+19
Jul 22 2018-10-22T00:
source share

Just make sure the folder you are working in is added to the path you built:

right-click Your folder, β†’ build Path β†’ Use as source Folder

and now he should find main in it

hope this helps

+13
May 16 '13 at
source share

I had the same problem. I tried all kinds of things. And I found out that

  • My .java files were not linked and
  • they were not placed in the 'src' folder.

What I've done:

Project Properties -> Java Build Path -> Source

  • Removed 'src' source folder that was empty using the Delete option
  • Added source containing my source .java files using the "Add Folder" option

This solved the error.

+5
Jun 12 '14 at 4:12
source share

What you need to do is create a Java project, but make sure you put this file in the batch file of this project, otherwise you will encounter the same error.

enter image description here

+3
Feb 09 '11 at 10:15
source share
 *** 

Just close and reopen

*** Your project is in an eclipse. Sometimes there are problems with binding. It solved my problem

+3
Feb 26 '16 at 8:12
source share

This code is valid. Have you tried to compile it manually with scalac? In addition, you called your file "address book", all lowercase, how is the name of the object?

In addition, I found that Eclipse, for some reason, sets the main class as ".addressbook" instead of "address book".

+2
Jul 11 '09 at 14:39
source share

Fast decision:

First, exclude the package: Right-click the source package β†’ Build Path β†’ Exclude

Then turn it back on: Right-click the source package β†’ Build path β†’ Enable

+2
Feb 20 2018-11-21T00:
source share

you should create a file

selecting the file name on the right side,

under which the src folder will be found with their right mouse button select β†’ class option

their file must be created

+2
Aug 11 '11 at 11:48
source share

You can try to run the main function from the eclipse sidebar.

solution

+2
Apr 01 '15 at 20:15
source share

I also had this problem. The solution is to make sure that eclipse created the project as a Java project. Just create a new Java project and copy your class to the src folder (and import the possible dependencies). This should fix the problem.

+1
Apr 15 2018-10-15T00: 00Z
source share

The correct answer: the Scala library must be before the JRE library in the build path.

Go to Java Buildpath> Order and Export and Move the Scala Library to the Top

+1
Feb 23 '11 at 4:22
source share

I had this problem with a Java project that I imported from the file system (under Eclipse Helios). Here's a hint: src code did not compile at all since the "bin" directory did not appear.

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

The project providing "The editor does not contain the main type" had this as "buildSpec" in the .project file:

 <buildSpec> </buildSpec> 

But the working draft had it like "buildSpec":

 <buildSpec> <buildCommand> <name>org.eclipse.jdt.core.javabuilder</name> <arguments> </arguments> </buildCommand> </buildSpec> 

I copied this and the imported project worked.

I know my answer is for Java, but the same could be a problem for your Scala project.

+1
Mar 12 '14 at 0:28
source share

Maybe the file you created is located outside the src (source) folder. Attempting to call a class object (from a file located in the src folder) from a .java file outside the original folder results in the same error. Copy the .java file to the source folder, and then create it. The error will disappear.

+1
Mar 21 '14 at 6:52
source share

Make sure your .java file is present either in the str package or in another package. If the java file with the main function is outside of all packages, this error occurs.

+1
Jul 01 '14 at 8:46
source share

I had the same problem. I had the main class from the src package, in a different folder. I move it and fix the folder and decide

+1
Aug 05 '15 at 16:08
source share

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

+1
Feb 12 '16 at 1:19
source share

This can be a problem in the Java Build path. Try the following steps:

  • Go to project properties
  • Go to java build path
  • Go to the "Source" tab and add the src project folder

This should solve the problem.

+1
Jan 04 '17 at 2:09 on
source share

If this is a maven project, please check that the java file is created in src / main / java

If you do not receive, please change the JRE path and create java files in the specified folder structure

+1
Apr 26 '17 at 13:06 on
source share

For me in Eclipse 3.6, this problem occurs when my main method is not publicly available. I caused the problem by having the main method:

 static void main(String[] args) 

Dubugger could not discover this himself. I am very surprised that Eclipse missed this.

0
Jun 21 '11 at 3:28
source share

Follow these steps:

  • Backing up all your .java files to another location
  • delete whole java project
  • Create a new java project by right clicking on the root directory and clicking on the new
  • restore all files to a new location!
0
Jan 23 '12 at 15:57
source share

In the worst case, create the project again with all the imports from the start. In my case, none of the other options worked. This type of error indicates an error in the project settings. Once I managed to solve this, but as soon as further development was done, the error returned. Reproducing everything from the very beginning helped me understand and optimize some links, and now I'm sure that it works correctly.

0
Jun 20 '12 at 8:19
source share

File β†’ Import β†’ Existing projects in the workspace β†’ Select β€œArchived archive” β†’ Browse and find the file β†’ Finish. If he already imported some other way, delete it and try so. I had the same problem until I tried this.

0
Apr 04 '13 at 0:52
source share

One more thing to check: make sure your source file contains the correct package declaration corresponding to its subdirectory. The error mentioned by the OP may be visible when trying to run the "main type" declared in the file in a subdirectory, but the package instruction is missing.

0
Nov 28 '13 at 22:45
source share

I also have this problem after I changed the source folder. The solution that worked was to simply edit the file and save it.

0
Aug 24 '14 at 10:32
source share

Try Update Project. As soon as I did this, the option "Run from Java" appeared.

0
Oct 25 '15 at 20:56
source share

In my particular "Hello World" case, the cause of this problem was the fact that my main() method was inside the Scala class .

I put the main() method in a Scala object and the error went away.

This is because a Scala object in terms of Java is an object with only static elements and methods inside.

This is why Java public static void main() in Scala must be placed under object .

(Scala class cannot contain static code inside)

0
Jan 28 '16 at 20:46 on
source share

Due to an error: "The editor does not contain the main type"

Error encountered in: Eclipse Neon

Operating System: Windows 10 Pro

When copying source folders from the thumb and leave the Eclipse_Projects.metadata folder.

In addition to the new installation, you will need to make sure that you merge the files from (Thrumb-drive) F: Eclipse_Projects.metadata.plugins.

These plugins are bits and pieces of library code taken from the SDK when creating the class. I really all depend on what you import javax.swing. *; ----- to your file. Since you are transferring it, be sure to combine ------ Eclipse_Projects.metadata.plugins ------ manually with a simple copy and paste, while accepting the skip function for existing plugins in your folder.

For windows 10, you can find your working folders according to a similar hierarchy of files.

C: Users> Mikes Laptop> workspace> .metadata> .plugins <--- merge plugins here

0
Nov 16 '16 at 6:30
source share
  • one
  • 2



All Articles