Can't compile java class in Intellij Idea due to “cannot find symbol class X” error

前端 未结 6 927
暖寄归人
暖寄归人 2021-02-07 00:47

I created new Java module from scratch in my project. \"create \'src\' folder\" was selected in module creation wizard. There is single \"com\" package in source folder which co

相关标签:
6条回答
  • 2021-02-07 00:53

    Right click project: Maven -> Reimport

    This worked on Intellij Mac.

    0 讨论(0)
  • 2021-02-07 01:04

    Try compiling the whole project (or at least class B) first.

    If you compile only class A, class B cannot be found because it hasn't been compiled yet (therefore, no bytecode B.class file exists).

    This is not intuitive, but true. IDEA doesn't automatically compile dependant classes when you compile single class.

    0 讨论(0)
  • 2021-02-07 01:08

    If a class within a package is dependent on another class in the package, you need to create a classpath. Otherwise, the compiler does not know that the other class actually exists. Your IDE probably knows inherently that the classes are in the same package, which is why it isn't showing any errors.

    You can resolve this issue most simply by supplying both classes as arguments to the compiler (I'm not familiar with the tool you're using to compile so this may not be possible), or by compiling a class outside the package that imports package 'com'. Both of these will create the classpath file along with the class files.

    0 讨论(0)
  • 2021-02-07 01:10

    "right-click on project -> compile"

    This did solve the same problem for me.

    0 讨论(0)
  • 2021-02-07 01:10

    Select Build -> Rebuild Project, it works for me!

    0 讨论(0)
  • 2021-02-07 01:19

    If the problem can not revolve by invalid retart, or rebuild projet. however the maven clean install build well.

    Sometimes, the cause is tomcat's tasks. If ur maven build well, then there is no reason that error cant find symbol. So you can edit tomcat conf, check if there is task before launch was setting, just delet these tasks. Tomcat will only take the maven build.

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