Sturm
Sturm

Reputation: 759

Editor does not contain a main type, even though it does

I've installed Eclipse on a brand-new PC and copied over all of my projects from an old PC's workspace to the new one. Everything is set up the way that it should be as far as I can tell, however, the project refuses to run. I either get the message Editor does not contain a main type or a Select Java Application window appears with a list of a bunch of things, none of which are my application.

This project works perfectly fine on two other computers--one is a Mac, the other Windows.

The Build Path for all three computers is identical.

Yes, the public static void main(String[] args) method exists and has for years.

Java is installed, and it's the latest jdk-11.0.3.

Nothing has been changed, except that this is a new installation of Eclipse on a new PC.

Editor does not contain a main type in Eclipse: I have tried many of the suggestions here; none work.

Error: Selection does not contain a main type: Folder is already set as a source folder. No help.

Editor does not contain a main type: I don't work with Scala. Irrelevant.

I have not found anywhere else I can turn. No chat groups (Slack / Discord) appear to exist for Eclipse nor Java development.

Edit

Here are some supporting screenshots.

First, showing that the file structure is sound:

File structure is sound

And to show that the Build Path is configured correctly:

Build Path configured correctly

Finally, sometimes I will get this message instead of the "Editor does not contain a main type" error:

Select Java Application dialog

Upvotes: 0

Views: 313

Answers (2)

Sturm
Sturm

Reputation: 759

It's a bug.

Turns out that all of my frustration is due to a bug introduced in Eclipse 4.11.

When running Eclipse 4.11 with JDK 11, sometimes a program that would normally run fine throws that error message. Thus, a simple downgrade to Eclipse 4.10 fixes the issue. (4.12 supposedly also fixes the issue, but it is still a Release Candidate as of this posting, so I'd rather avoid it for now.)

Credit for discovering this goes to Nune Isabekyan on The Java Specialists' Slack.

Upvotes: 0

jhenrique
jhenrique

Reputation: 868

That error is happening because your Sample.java is not inside your src folder. Cut and paste (or just move) your class into your src folder and try again. Regards!

enter image description here

It will look like the image below when you are done.

enter image description here

Upvotes: 2

Related Questions