Accepted answer

i hope you are trying to run the main class in this way, see screenshot:
screenshot of eclipse file context menu

if not, then try this way. if yes, then please make sure that your class you are trying to run has a main method, that is, the same method definition as below:

public static void main(string[] args) {
    // some code here

i hope this will help you.


i ran into the same issue and found that there was an extra pair of braces (curly brackets) enclosing public static void main(string args) { ... }. this method should really be at the top scope in the class and should not be enclosed around braces. it seems that it is possible to end up with braces around this method when working in eclipse. this could be just one way you can see this issue when working with eclipse. happy coding!


i had this happen repeatedly after adding images to a project in eclipse and making them part of the build path. the solution was to right-click on the class containing the main method, and then choose run as -> java application. it seems that when you add a file to the build path, eclipse automatically assumes that file is where the main method is. by going through the run as menu instead of just clicking the green run as button, it allows you to specify the correct entry-point.


when you save your file, make sure it has the extension .java. if it does not, eclipse won't know to read it as a java file.


i had this issue because the tutorial code i was trying to run wasn't in the correct package even though i had typed in the package name at the top of each class.

i right-clicked each class, refactor and move to and accepted the package name suggestion.

then as usual, run as... java application.

and it worked :)


you must check this as well, go to java build path -> config build path, check that jre system library [java se -version] is check marked, try running the code again. this fixed my issue.


in my case i was using ant to perform the build, and clearly had the class setup in the build.xml file:

<target name="jar">
  <jar destfile="ec-stats.jar" includes="bin/**,src/**">
        <attribute name="main-class" value="my.package.mystatistics" />

but it still kept giving me the same error, until i right-clicked on the folder in eclipse and chose build path -> use as source folder.

enter image description here

see also error: selection does not contain a main type


solved the issue as following:

  1. going in properties of the project
  • 1.1) inside "java compiler": chose the: "compiler compliance level:" to a specific version of jdk (in my case i choosed 15)

  • 1.2) inside "java build path", in the tab "libraries", at the modulepath: change the "jre system library" to the same of the version you choosed at step 1.1 above (in my case i picked jdk 15)

  1. run the java file that contains a main method


this can be resolved in two steps if you are using eclipse ide.

๐Ÿ‘‰ step i: right click on the project and click maven > choose up-date project

๐Ÿ‘‰ step ii: select the project the click ok button

enter image description here

hope this helps.โœ”


you must place all your files ( under the root folder src.


make sure the main in public static void main(string[] args) is lower case. for me it didn't work when i had it with capital letter.


put your main java class file in src/main/java folder and check if there is not any error in 'java build path' by following right click on project and select java build path->source.


if you are working with a maven project you have to understand the fact that directory layout is bit different. in this the package name must be src/main/java.

for this update your source folder by right click on project root folder -> properties -> java build path -> source tab. here remove all other source folders as they might have been added in wrong manner. now, select project /src/main/java as the source folder. add and apply the changes. now refresh your workspace using f5.

this should fix the issue of not recognizing a main type.


right click > run as > run configurations

in this screen if your "main class" text field is empty, then add the class name by clicking "search" button on the right side of the text field and choose the class file. and then click "run" button on the bottom of the configuration screen. that's it


few things to check out:

  1. do you have a main package? do all of your classes are under this package?
  2. do you use a main class with public static void main(string[] args)?
  3. do you declare: package ; in your main class?
  4. you can always clean the project before running it. in eclipse - just go to project -> clean then run the app again.


i ran into the same problem. i fixed by right click on the package -> properties -> java build path -> add folder (select the folder your code reside in).


i am running eclipse from ubuntu. had this same problem and was able run the program through terminal. so i just moved the existing public static void main(string[] args) { just below the class declaration (it got automatically formatted by eclipse) and the next launch was successful. then moved the main method back to where it was before and it worked fine this time.


i had this problem in two projects. maven and command line worked as expected for both. the problems were eclipse specific. two different solutions: project 1): move the main method declaration to the top within the class, above all other declarations like fields and constructors. crazy, but it worked. project 2): the solution for project 1) did not remedy the problem. however, removing lombok imports and explicitly writing a getter method solved the problem

conclusion: eclipse and/or the lombok plugin have/has a bug.


looks too late to answer but might help someone,

having same problem i solved it by following steps:::::

select main class in eclipse then click on window in menu bar,

window-->show view-->select outline

right click on main(string[]):void then run as --> java application

image reference for running main method

by doing this you can run the main method directly. this worked for me


the entry point for java programs is the method:

public static void main(string[] args) {

if you do not have this, your program will not run.


i resolved this by adding a new source folder and putting my java file inside that folder. "source folder" is not just any folder i believe. its some special folder type for java/eclipse and can be added in eclipse by right-click on project -> properties -> java buld path -> source and add a folder


the other answers are all valid, however, if you are still having a problem you might not have your class inside the src folder in which case eclipse may not see it as part of the project. this would also invoke the same error message you have seen.


right click on the folder where you put your main class then click on build path --> use as source folder.

finally run your main file as java application. hope this problem will be solved.

if the option 'use as source folder' is not visible then inside the 'build path' select the option 'remove from build path'. this will allow 'use as source folder' option to appear in the 'build path'.

Related Query

More Query from same tag