IntelliJ can't find classes in same package when compiling
Asked Answered
S

7

16

As an extension to my previous question (IntelliJ can't find depencency when compiling, but can in editor.) which got solved, I now have a new issue which has sprung up.

Within the same packages, references to other classes are showing up with errors:

enter image description here

As you can see in the picture, there is happening at the line involving the BifCreatorController, even though that class is in the same package as the BifCreatorView.

Just like my previous question, I am failing to understand why IntellJ is spitting out those errors. This project works just fine in Eclipse, but I am looking to start moving away from eclipse.

Saunders answered 13/1, 2016 at 22:27 Comment(0)
O
7

This is because BifCreatorController is excluded from compilation (see the small "X" top-left icon near to the file name). One reason would be the file got some errors while compiling, IDEA proposed to exclude it from compilation and you had accepted.

Go to "File > Settings > Build, Execution, Deployment > Compiler > Excludes" and remove it from there.

Outplay answered 14/1, 2016 at 8:31 Comment(2)
Awesome! And wow, I had no idea IntelliJ would do that exclude. I feel pretty strongly it should have given me some kind of warning/info message about this. Oh well... Once I learn IntellJ more, perhaps I'll be able to predict issues like this. ThanksSaunders
:) You just need some time getting accustomed to it, and btw if you're an Eclipse user, you may find this migration guide (from IntelliJ official site) valuable: jetbrains.com/idea/help/eclipse.htmlOutplay
C
33

Got same problem today. Rebuilding or restarting both didn't work for me. In the end, I tried to rename the class, problem solved! Then I rename the class to the name I want, everthing was fine!

Chemosmosis answered 6/3, 2020 at 12:42 Comment(5)
Since it happens very rarely, this is a nice solution that worked perfectly for me.Laspisa
So I was like how is this going to work. I went to the class just typed something random and then deleted the random text and it indexed the class???? I have no idea how or why. I literally did invalidate cache and restart which normally works but it did not work today. This worked and I'm forever thankful to you.Ruination
Legendary. Just resolved an hour of head-pounding and frustration after 2 restarts with no successKowalczyk
Renaming the class and renaming again back to original one did the trick. Thanks!Abramson
Works with "missing" interfaces as well.Vantage
O
7

This is because BifCreatorController is excluded from compilation (see the small "X" top-left icon near to the file name). One reason would be the file got some errors while compiling, IDEA proposed to exclude it from compilation and you had accepted.

Go to "File > Settings > Build, Execution, Deployment > Compiler > Excludes" and remove it from there.

Outplay answered 14/1, 2016 at 8:31 Comment(2)
Awesome! And wow, I had no idea IntelliJ would do that exclude. I feel pretty strongly it should have given me some kind of warning/info message about this. Oh well... Once I learn IntellJ more, perhaps I'll be able to predict issues like this. ThanksSaunders
:) You just need some time getting accustomed to it, and btw if you're an Eclipse user, you may find this migration guide (from IntelliJ official site) valuable: jetbrains.com/idea/help/eclipse.htmlOutplay
U
5

I had the same problem, i cleared the cache and restarted but it did not solve the problem. Then i right clicked the not found class and selected Recompile and after recompilation the problem was solved.

Unconventionality answered 22/10, 2019 at 14:32 Comment(0)
F
5

For those who can't beat the trouble i suggest switching to maven because it's predictive:

Maven > Runner > Delegate IDE build/run actions to Maven

Facing answered 2/4, 2021 at 16:25 Comment(3)
The screenshot suggests that this is not a maven project. Delegating to maven thus cannot be a solution.Minnick
in my case this is the ONLY silver bullet for intellij idea version i'm allowed to install.Facing
only this method worked! ThanksOaks
H
3

Another reason is the cache problem.

Go to -> File -> Invalidate Caches / Restart ...

invalidate cache and restart

Hennessey answered 12/4, 2022 at 6:39 Comment(0)
A
0

Thanks to @liuyong for the tip. In my case it happened with A LOT of classes, so renaming all of them would have been a bit cumbersome.

Then I decided to rename the base package (I just added a letter at the end), compiled the code and then renamed back to the original one.

It worked here too. The problem didn't happen again when switching branches.

Allieallied answered 4/8, 2023 at 13:40 Comment(0)
B
0

Nothing else worked for me, but this fixed it

Build -> Rebuild Project

enter image description here

Baccarat answered 10/6, 2024 at 10:58 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.