15

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.

Community
  • 1
  • 1
E.S.
  • 2,733
  • 6
  • 36
  • 71

6 Answers6

27

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!

liuyong
  • 987
  • 10
  • 19
  • Since it happens very rarely, this is a nice solution that worked perfectly for me. – Tomáš Nesrovnal Jul 03 '20 at 06:41
  • 1
    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. – Ganesh Aug 01 '20 at 00:28
  • 2
    Legendary. Just resolved an hour of head-pounding and frustration after 2 restarts with no success – takanuva15 Jan 25 '21 at 21:54
  • 1
    Renaming the class and renaming again back to original one did the trick. Thanks! – Preeti Joshi Jan 28 '21 at 07:07
  • Works with "missing" interfaces as well. – Martin Ivančič Jun 28 '21 at 12:42
6

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.

Ivaylo D. Ivanov
  • 3,783
  • 1
  • 12
  • 16
  • 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. Thanks – E.S. Jan 14 '16 at 18:35
  • :) 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: https://www.jetbrains.com/idea/help/eclipse.html – Ivaylo D. Ivanov Jan 15 '16 at 07:54
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.

velocity
  • 1,630
  • 21
  • 24
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

Simon Logic
  • 330
  • 4
  • 10
2

Another reason is the cache problem.

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

invalidate cache and restart

i.karayel
  • 4,377
  • 2
  • 23
  • 27
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.

Paulo Pedroso
  • 3,555
  • 2
  • 29
  • 34