Reputation: 2319
I make this call to a static singleton instance from the class GameManager.java
.
HUD.getInstance().update(timeDelta);
HUD.java
contains the HUD
class as well as two other related classes, HUDTextElement
and HUDElement
. All the classes are in the same root path ../src/org/mypackage
.
However, when compiling this project in IntelliJ I get cannot find Symbol HUD on the line I make the HUD.getInstance()
call.
This exact same code compiles just fine in Eclipse, any idea what the problem is?
Upvotes: 184
Views: 332937
Reputation: 87
I had this problem and it was resolved by adding the following highlighted block into the pom.xml file.
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<build>
<plugins>
<!-- Compiler plugin for specifying Java version -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
</plugins>
</build>
Remember to update maven afterwards
Upvotes: 2
Reputation: 371
For me, I excluded a file in build time by mistake which caused this problem. Followed these steps to remove it from excludes:
https://stackoverflow.com/a/65753260/8963778
Upvotes: 0
Reputation: 631
In my case, all packages of lombok were imported I removed this code and imported each required package separately and the problem was solved.
import lombok.*; // <-- I just removed this line and reimport packages
I also don't know why this solved the problem I tried all the solutions in the comments here, but it didn't work.
Upvotes: 0
Reputation: 44
In my case, I accidentally added a file to the compiler exclusion list somehow. I went to Preferences -> Compiler -> Excludes, and then removed the file from the exclusion list.
Upvotes: 0
Reputation: 25
Make sure the "Target bytecode version" in the Java Compiler settings is set to a java version that contains the feature you're trying to use. This value is normally set to "Same as language level" but can be overridden for individual modules. When that happens the code editor will show warnings based on the other language settings but the compiler will generate bytecode for the specified java version. If those language settings don't match it can be difficult to diagnose the problem.
Upvotes: 1
Reputation: 176
In my case, it had nothing to do with the project build or the JDK version mismatch for the project and modules. Giving some context about what I was building:
public static final Integer
type instead of the **int**
type. This is a compilation issue as @Size would need constant values for min and max.Upvotes: 0
Reputation: 61
In my case,
Upvotes: 1
Reputation: 464
For me: I ran an mvn clean install
in console(not with embedded IntelliJ maven). Then when I tried again in Intellji maven, it was working fine.
Upvotes: 1
Reputation: 2480
Delete all the contents inside ~/.m2
. Start intellij-idea
.
(Using IntelliJ IDEA 2021.3 (Community Edition))
Upvotes: 0
Reputation: 1251
I solved this problem doing right click on Java Folder and Rebuild
Upvotes: 17
Reputation: 2801
I tried everything and nothing worked for me. So, after wasting a couple of hours, I decided to upgrade the IntelliJ idea version, and finally, it worked!
Upvotes: 0
Reputation: 51
Once when Maven Reimport, Rebuild Project, Invalidate caches didn't help I deleted subfolders artifacts
and libraries
from .idea folder, not whole one, so I saved custom project settings.
...and when nothing written here helps check idea.log file as posted here
Upvotes: 0
Reputation: 494
For me, the error was coming from @RequiredArgsConstructor(onConstructor = @__(@Inject))
, and the message was cannot find symbol __
. The error message right above this was "java: You aren't using a compiler supported by lombok, so lombok will not work and has been disabled".
Adding argument below in VM options worked as suggested here worked for me.
-Djps.track.ap.dependencies=false
Upvotes: 2
Reputation: 69
This works for me, say class A depends on class B(and class c, d etc) but the error throws on class A which does not have any errors. So I try to compile class A alone first ->it shows error on the package of class B. So tried to compile whole package of class B. Now it throws which is the exact error class(on my case class B had error). Usually Intellj shows the exact error class with line number when compile/build. On some occasions it throws error in wrong place/class. Have a try.
Upvotes: 0
Reputation: 3302
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
If everything is fine, you can try following solutions in given order
Recompile the file/module
If that didn't fix the issue, try refreshing maven dependency and building the project using Maven -> Reimport
and Build -> Rebuild Project
Try mvn clean install -DskipTests
Try invalidating the IntelliJ cache and restarting the IDE, using File > Invalidate caches/ restart
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.
Upvotes: 20
Reputation: 576
In my case, I had a problem with finding a class from another module. In pom.xml
, I just had this dependency with <scope>compile</scope>
specified. Removing this line helped.
Upvotes: 0
Reputation: 1599
For me was a problem with Lombok, because it requires Annotation Processing to be enabled. You can find this checkbox on Settings > Build > Compiler > Annotation Processors
Upvotes: 3
Reputation: 1562
I'm seeing a lot of answers proposing a build or a re-build but just in case this don't fix your problem just notice that IDEA can detect a method but it will not compile in case you have a new
before as it will be expecting the instance.
Upvotes: 0
Reputation: 477
If you are using Lombok, make sure you have enabled annotation processing.
Upvotes: 3
Reputation: 1980
For me - I tried these steps(Invalidate Cache & Restart, Maven Reimport)) but they didn't work. So I deleted the .idea
, .settings
, and .project
folder and tried - it worked.
Upvotes: 20
Reputation: 2265
This happened to me when I deleted a folder and then copy-pasted it back to the project.
Right-click project folder -> Rebuild
worked for me.
Upvotes: 11
Reputation: 36
I know this thread is old but, another solution was to run
$ mvn clean install -Dmaven.test.skip=true
And on IntelliJ do CMD + Shift + A (mac os) -> type "Reimport all Maven projects".
If that doesn't work, try forcing maven dependencies to be re-downloaded
$ mvn clean -U install -Dmaven.test.skip=true
Upvotes: 2
Reputation: 2580
recompiling the main Application.java class did it for me, right click on class > Recompile
Upvotes: 4
Reputation: 191
For my case, the issue was with using Lombok's experimental feature @UtilityClass in my java project in Intellij Idea, to annotate a class methods as "static". When I explicitly made each method of the class as "static" instead of using the annotation, all the compilation issues disappeared.
Upvotes: 1
Reputation: 391
I had to right-click the project, and select "Reimport" under the "Run Maven" submenu.
Upvotes: 7
Reputation: 25
I was having the same problem except that I was importing the classes for which dependencies were not resolving somehow. I refreshed maven projects, Rebuild Project. It still did not resolve. Looks like IntelliJ was caching something incorrectly. I restarted IntelliJ and that resolved the dependencies. I guess it cleared the cache somehow.
Upvotes: 0
Reputation: 10744
Sometimes the class you want is in the test
source directory. Happened to me, anyway…
Upvotes: 0
Reputation: 21278
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.
Upvotes: 0
Reputation: 57
Since this is the first hit on Google searching for "intelliJ cannot find symbol" error, I'm gonna throw in my solution as well.
The problem for me was that my project originated from Eclipse, and some files contained dependency on classes that were generated in src/generated-sources
by specifications in pom.xml. For some reason, this was not properly executed when I first opened the project and rebuilding/re-importing did not help, so the files were never generated.
The solution was to right-click on the module, and select Maven -> Generate Sources and Update Folders
That solved the issue and I could compile.
Upvotes: 0