Fix Error “editor does not contain a main type” in Eclipse

So in this tutorial, We will know that what kind of reasons can be for getting this error “Editor does not contain a main type” and we will see how to fix this error.

Basically, this type of Error means your Editor is not able to find the “main” method in any of your current program classes. The editor shows this error because when you want to run the project, at that time, the interpreter couldn’t find the main function to start the execution of the program.

Reasons for Error

So there can be various reasons causing this error:

  • If you have not declared the main method in your program, at that time it will be compiled successfully but while running the program, it will throw this error.
  • It can occur if the .java file has not linked or has not placed in the src
  • If you have not added a build path in the same folder where you are working.
  • If .class file or project file is not present in your workspace at that time it will occur.
  • If you are using Eclipse for java Programming and you have not declared the main method as public.
  • If the program is not compiled correctly.

Solutions

  • First, you should check that you have declared the “main” method in your program or not if you have not then you should write the “main” method inside your class.
  • If you are using eclipse and you have declared the “main” method in your program and you have written it inside the class then you have to check that you have added the build path or not. If you have not added then:- go to project properties -> Choose java build path -> Click on the source.
  • If the editor is not able to find the Source folder then you have to follow these steps:-
    1. Right-click on Project folder and go through the Properties
    2. Choose ‘Java Build Path’.
    3. Click on the ‘Sources’ tab on top.
    4. Click on ‘Add Folder’ on the right panel.
    5. Select your folders and apply them.
  • If you have not to clean your project then you should try this, Project -> Clean, or you can follow these steps on the command line -> run “eclipse -clean  -refresh.
  • In the last, confirm that you have declared the main method with “public” access specifier, like ->

  • And if you are sure about this that you have written the main method and code correctly then delete the current program file after copying your code and create a new file and paste in it.
  • Please Check that .class file is present in your workspace or not, If there is not present that file then you should add that file by compiling it before running the Project.
  • Wherever you have written the “main” method, you should sure about this that It is present inside the src folder, if It’s not then you have to place the “main” method inside the src folder and after that, you could simply run the Program.
  • If the program is not compiled correctly that time project does not contain an executable main class, So that time you have to compile the program correctly.

That was all about the reasons and solutions to this “Editor does not contain a main type”. If you have any queries or suggestions please leave in the comment below. We would love to help.

1 thought on “Fix Error “editor does not contain a main type” in Eclipse”

Leave a Comment

Your email address will not be published. Required fields are marked *