0

我是 Java 新手。

我所有的源文件(例如 TreeJPanel.java、Tree.java)都在一个名为 jview 的目录中,它们之间存在依赖关系。当我尝试编译时

javac jview/TreeJPanel.java
我明白了:

jview/TreeJPanel.java:39: cannot find symbol
symbol  : class Tree
location: class TreeJPanel
  protected Tree tree;
            ^
jview/TreeJPanel.java:41: cannot find symbol
symbol  : class Tree
location: class TreeJPanel
  public Tree getTree() {
         ^
jview/TreeJPanel.java:45: cannot find symbol
symbol  : class Tree
location: class TreeJPanel
  public void setTree(Tree tree) {

有 15 个类似的错误。我以为我不需要从同一目录中显式导入?我究竟做错了什么?我的问题很可能表明缺乏对 Java 的概念理解——请随时指出。谢谢!

4

3 回答 3

0

Was Tree.java first compiled into Tree.class? when TreeJPanel.java was trying to compile, it was searching for it.

于 2012-11-21T04:10:25.823 回答
0

尝试一起编译这两个文件:

      javac jview/Tree.java jview/TreeJPanel.java
于 2012-11-21T04:16:38.837 回答
0

因为这很简单,你应该将 Tree 类导入 TreeJpanel 类

您的代码应如下所示

import jview.Tree;

Class TreeJPanel { .... 
于 2012-11-21T04:17:04.270 回答