Search code examples
intellij-ideapackageproject-structure

Package name does not correspond to the file path - IntelliJ


I'm trying to import a project from VCS (well, I'm doing it for the first time actually) and this is my (imported) project's structure:

The file structure

BTW. this screen is made after many tries of changing these directories' properties (in their context menus).

In these source files' I have a following error:

The error in the editor

One time it had nothing against badugi.client but it reported this error only in badugi.server. I have completely no idea how it works...

Also classes in the same directories do not see each other.

Error

This is a code from ClientWorker class which is located (as you can see in the first image) in the same directory as Server so it should know what Server is.

I'm pretty sure this code worked well in my friend's IDE. How do I configure IntelliJ to make it work?


Solution

  • Judging from the directory structure, you have two packages client and server, but the code expects packages badugi.client and badugi.server.

    Here is a way to fix it:

    1. Position your cursor to the underlined package statement (package badugi.server)
    2. Hit ALT + ENTER
    3. Select option Move to package badugi.server. This will automatically fix your directory structure to match the declared package

    or

    1. Right click src in Project explorer
    2. Select New/Package and create package badugi
    3. Select client and server packages and drag them to the badugi package