【问题标题】:I keep getting an error that say "cannot find symbol" when using a class from another file使用另一个文件中的类时,我不断收到一条错误消息,提示“找不到符号”
【发布时间】:2020-08-11 17:59:12
【问题描述】:

我正在尝试在与我的四叉树文件不同的文件中创建四叉树。

Quadtree<String> blocky = new Quadtree<String>(rand.nextInt(5), new Quadtree.Boundry(0,0,rand.nextInt(750),rand.nextInt(750)));

但是,我在终端中不断收到此错误。

error: an enclosing instance that contains Quadtree.Boundry is required

当我在没有“四叉树”的情况下这样做时。在Boundry之前,我得到了

error: cannot find symbol

对我能做什么有什么建议吗?

编辑:

这是我的四叉树类的一部分

import java.util.ArrayList;

公共类四叉树 {

class Node{
    int x, y;
    E elem;
    Node(int x, int y, E elem)
    {
        this.x = x;
        this.y = y;
        this.elem = elem;
    }

}

final int QT_NODE_CAPACITY = 64;
int level = 0;
ArrayList<Node> nodes;
public Quadtree NW = null;
public Quadtree NE = null;
public Quadtree SE = null;
public Quadtree SW = null;
Boundry bdry;

public Quadtree(int level, Boundry bdry)
{
    this.level = level;
    this.bdry = bdry;
    nodes = new ArrayList<Node>();
}

class Boundry
{

    public int getXMin(){
        return xMin;
    }
    public int getXMax(){
        return xMax;
    }
    public int getYMin(){
        return yMin;
    }
    public int getYMax(){
        return yMax;
    }

    public Boundry(int xMin, int xMax, int yMin, int yMax)
    {

        super();
        this.xMin = xMin;
        this.xMax = xMax;
        this.yMin = yMin;
        this.yMax = yMax;

    }

    public boolean containsCoordinate(int x, int y)
    {
        return (x >= this.getXMin() && x <= this.getXMax() && y >= this.getYMin() && y <= this.getYMax());
    }

    int xMin, xMax, yMin, yMax;
}

【问题讨论】:

  • 向我们展示您的四叉树。

标签: java quadtree


【解决方案1】:

Boundry 必须声明为 static 才能被实例化,而不是限定为 Quadtree 的特定实例。

【讨论】:

  • 知道了。谢谢。
  • @Enic1938 太好了!如果这能解决您的问题,您介意接受答案吗?
猜你喜欢
  • 2021-07-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-14
  • 1970-01-01
  • 2021-02-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多