Niv Kor
Niv Kor

Reputation: 192

"Error: Could not find or load main class" after renaming all the packages

I've probably just done something quite stupid, and renamed / changed the order of the packages in my project manually via the src folder at eclipse workspace.

After doing that I had to fix every class seperately and rewrite the package it belongs to, on its top line.

The problem is that now, it seems like my project doesn't even recognize its classes. they don't show an error if they have one, while the project itself always shows a red error. When I run the project I get

Error: Could not find or load main class".

I tried Project -> Clean or manually choosing the main class, but it didn't work.

Upvotes: 0

Views: 2105

Answers (1)

CrimsonMike
CrimsonMike

Reputation: 283

A good explanation of this error can be found here:

An explanation

Another explanation

By manually renaming package you change all references (even those you might not know about - for example auto-imports). It is usually never a good idea to rename manually in eclipse or even the explorer (on windows). Use "Refactor" to do this - right-click the package and select this option. This will rename all references to the package and the package itself.

Changing the order of the packages manually will cause the same issue. Package names will not be correct anymore. Therefore, you should let eclipse do the work for you by selecting the appropriate option for what you want to achieve.

Upvotes: 1

Related Questions