在同一个包中找不到类

在同一个包中找不到类

本文介绍了在同一个包中找不到类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编译Board.java,它与Hexagon.java位于同一个包(和目录)中,但我收到此错误:

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;

Board.java的前几行:

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;

Hexagon.java的前几行:

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?

谢谢

推荐答案

我很确定你'从错误的目录中编译。 您应该从源根目录编译,而不是从oadams_atroches目录中编译。

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.

看看这个bash-session:

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 ..

...并编译:

aioobe@r60:~/tmp/hex$ javac oadams_atroche/Board.java
aioobe@r60:~/tmp/hex$

这篇关于在同一个包中找不到类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 01:35