Getting “cannot find Symbol” in Java project in Intellij

前端 未结 24 842
清酒与你
清酒与你 2020-12-04 10:33

I make this call to a static singleton instance from the class GameManager.java.

HUD.getInstance().update(timeDelta);

HU

相关标签:
24条回答
  • 2020-12-04 11:23

    Make sure the source file of the java class you are trying to refer to has a .java extension. It was .aj in my case (I must have hit "Create aspect" instead of "Create class" when creating it). IntelliJ shows the same icon for this file as for "normal" class, but compiler does not see it when building.

    Changing .aj to .java fixed it in my case.

    0 讨论(0)
  • 2020-12-04 11:24

    recompiling the main Application.java class did it for me, right click on class > Recompile

    0 讨论(0)
  • 2020-12-04 11:24

    I faced the same problem, and there are a lot of solutions given in the answer, trying all these solutions took me quite some time, so here I would like to propose a methodical approach if you get this error.

    Check for the following things, create/update if something is missing

    1. src folder is marked as the source folder
    2. .imls files are present
    3. Annotation processing is enabled
    4. If you recently used @UtilityClass then it can also be the reason, Bug Link

    If everything is fine, you can try following solutions in given order

    1. Recompile the file/module

    2. If that didn't fix the issue, try refreshing maven dependency and building the project using Maven -> Reimport and Build -> Rebuild Project

    3. Try mvn clean install -DskipTests

    4. Try invalidating the IntelliJ cache and restarting the IDE, using File > Invalidate caches/ restart

    5. Delete the .idea folder and reimport the project

    Credit and Thanks to everyone who answered this question, you can refer to their answers for more description regarding each point.

    0 讨论(0)
  • 2020-12-04 11:25

    I had the same problem and fixed it by clicking File>Invalidate caches/ restart

    0 讨论(0)
  • 2020-12-04 11:25

    Thanks for the help so far, turns out the fix was to compile HUD.java first (right click on the file-> Compile HUD.java). After compiling the java file the rest of the project could be compiled without any problems.

    I don't really know why this fixed it, or why IntelliJ wouldn't do this automatically, but root error seems it has to do with IntelliJ not correctly handling having multiple classes in a single .java file.

    0 讨论(0)
  • 2020-12-04 11:26

    Select Build->Rebuild Project will solve it

    0 讨论(0)
提交回复
热议问题