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 symbol : class Hexagon location: class oadams_atroche.Board private Hexagon[][] tiles;
The first few lines of Board.java:
package oadams_atroche; import java.util.LinkedList; import java.util.Queue; import java.io.PrintStream; import p323.hex.*; public class Board implements Piece{ >---//Fields >---private int n; >---private Hexagon[][] tiles;
The first few lines of Hexagon.java:
package oadams_atroche; import p323.hex.*; public class Hexagon implements Piece{
I just cannot see what I am doing wrong. Any ideas?
Thanks
A Java file contains only one public class with a particular name. If you create another class with same name it will be a duplicate class. Still if you try to create such class then the compiler will generate a compile time error.
The compiler relies on the names of source files to find and compile dependent classes. It's possible (and common) to put more than one class definition into a single file, but there are some restrictions we'll discuss shortly. A class is declared to belong to a particular package with the package statement.
No, it cannot be.
Yes, you can import a class twice in Java, it doesn't create any issues but, irrespective of the number of times you import, JVM loads the class only once.
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$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With