Intellij Cannot resolve symbol on import

前端 未结 29 1741
耶瑟儿~
耶瑟儿~ 2020-11-30 18:10

This problem happens intermittently for different libraries and different projects. When trying to import a library, the package will be recognized, but the class name can\'

相关标签:
29条回答
  • 2020-11-30 19:08

    I found the source cause!

    In my case, I add a jar file include some java source file, but I think the java source is bad, in Intellij Idea dependency library it add the source automatic, so in Editor the import is BAD, JUST remove the source code in "Project Structure" -> "Library", it works for me.

    0 讨论(0)
  • 2020-11-30 19:10

    Intelli iDEA causes these stupid troubles @ times. Simple goto pom.xml , right click and do -> Maven -> Reimport.

    This should solve the problem.

    0 讨论(0)
  • 2020-11-30 19:12

    I found the following answer from @jossef-harush and @matt-leidholm useful from another link

    • in IntelliJ editor, click on the red keyword (Integer for example) and press ALT + ENTER (or click the light bulb icon)
    • select Setup JDK from the intentions menu

    IntelliJ intentions menu

    • click on Configure

    Project SDK selection dialog

    • In my case, the JDK path was incorrect (pointed on /opt/jdk1.7.0_51 instead of /opt/jdk1.7.0_65)

    Broken Configure SDK dialog

    • click on the ... and browse to the right JDK path

    Fixed Configure SDK dialog

    • let's clear the cache

    IntelliJ File menu

    0 讨论(0)
  • 2020-11-30 19:12

    Had the same problem till I noticed that the src folder was marked as root source instead of java! Changing to only the java (src/main/java) to be the source root solved my problem

    0 讨论(0)
  • 2020-11-30 19:12

    The same problem. If these methods not work. you can try to delete the lib from local maven repository, and reimport to pom .

    Finally it' fine for me.

    0 讨论(0)
  • 2020-11-30 19:13

    Right click on pom.xml file, go to Maven click on Reimport. I had similar problem and this worked for me.

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