Cannot find class in same package

后端 未结 3 649
清歌不尽
清歌不尽 2020-12-16 12:21

I am trying to compile Board.java, which is in the same package (and directory) as Hexagon.java, but I get this error:

Board.java:12: cannot find symbol
symb         


        
相关标签:
3条回答
  • 2020-12-16 12:29

    It works for me:

    cd SRC_DIRECTORY
    javac  -cp . PACKAGE/CLASS.java
    
    0 讨论(0)
  • 2020-12-16 12:36

    I'm quite sure you're compiling from within the wrong directory. You should compile from the source root-directory, and not from within the oadams_atroches directory.

    Have a look at this bash-session:

    aioobe@r60:~/tmp/hex/oadams_atroche$ ls
    Board.java  Hexagon.java
    aioobe@r60:~/tmp/hex/oadams_atroche$ javac Board.java 
    Board.java:12: cannot find symbol
    symbol  : class Hexagon
    location: class oadams_atroche.Board
        private Hexagon[][] tiles;
                ^
    1 error
    

    While if I go up one directory...

    aioobe@r60:~/tmp/hex/oadams_atroche$ cd ..
    

    ... and compile:

    aioobe@r60:~/tmp/hex$ javac oadams_atroche/Board.java 
    aioobe@r60:~/tmp/hex$ 
    
    0 讨论(0)
  • 2020-12-16 12:36

    Not sure about different platforms, but using Netbeans on Windows, it's often easiest to just create a project.

    If you're trying to compile from command line:

    javac -cp . *.java

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