Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
341 views
in Technique[技术] by (71.8m points)

java - Cannot find class in same package

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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$ 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...