LuminousNutria
LuminousNutria

Reputation: 2001

How can I get Eclipse to add a Default Package to an Existing Project?

I cannot run a program in Eclipse Photon (4.8.0). Eclipse keeps telling me that, "Editor does not contain a main type." Even though it clearly does. According to Package Explorer, the java file I'm trying to run is under the src folder, so Eclipse should be able to find it.

So, I think this is because my project doesn't have a default package. Or at least, not one that I can see.

My question is, how can I add a default package to an already existing project in Eclipse?

If you choose to down-vote this, please let me know why. I would like to improve my post if possible.

Here is a screenshot of my Package Explorer.

enter image description here

Upvotes: 0

Views: 4944

Answers (3)

Till Brychcy
Till Brychcy

Reputation: 2924

You cannot use the default package in a project which has a module-info.java. If you don't need the module system's features, just remove the module-info.java and you can develop as pre java 9.

Upvotes: 3

Azim
Azim

Reputation: 1724

In the Package Explorer panel, right click on your "src" folder, and create a new class. In the window that pops up to ask you for the name of the class (see the picture below), there is a section that has the name of the package. Not providing any name there, would result in the new class to be saved in the "default package". enter image description here Note that, default package means that there is no package to hold that class. This is just a way for eclipse to show you that this class is not kept in any specific directory in your computer. It will be stored right inside the "src" folder, next to other packages.

Upvotes: 0

Danny
Danny

Reputation: 340

You can't add a default package but you can add a package by right clicking on the folder and creating a new package and after that adding package "packagename"; on top of the file.

Upvotes: 0

Related Questions