如何修复“无法解决方法”?

问题描述 投票:-4回答:1

所以首先我有这个课程:

public float getPixel(int height, int width)
{
   return data[height][width];
}

public void setPixel(float value, int height, int width)
{
   if (value > getMax())
     value = getMax();
   if (value < 0)
    value = 0;
   data[height][width] = value;
}

private Image(String magicNumber, int height, int width, float max) {
  this.magicNumber = magicNumber;
  this.width = width;
  this.height = height;
  this.max = max;
  data = new float[height][width];
}
...
public Image clone()
{
  Image clone = new Image(getMagicNumber(), getHeight(), getWidth(), getMax());
   for (int i = 0; i < getHeight(); i++)
   {
     for (int j = 0; j < getWidth(); j++)
     {
        clone.setPixel(getPixel(i, j), i, j);
     }
   }
  return clone;
}

然后这堂课:

public class Filter {

    public Filter() {

    }

    public Image linearFilter(Image image, float[][] kernel)
    {
        Image filtered = image.clone();
        for (int i = 0; i < getHeight(); i++) 
        {  /* cannot resolve getHeight*/
            ...
        }
         return filtered;
    }
}

我有两个问题:

1)为什么我不需要创建类Image的实例。在这里,我已经可以使用filtered.setPixels ...

2)如何使用“无法解决方法”解决问题?

java class methods
1个回答
-1
投票

我无法从你的帖子中说出来,因为你发布的第一个片段似乎不是一个完整的类,而是它的一部分。我假设你有一个Image类,而Image类有一个名为getHeight()的方法。

在for循环条件for (int i = 0; i < getHeight(); i++)中,你很可能想要将getHeight()更改为filtered.getHeight(),因为getHeight()Image类中的一种方法,而filtered(大概)是Image类型。

© www.soinside.com 2019 - 2024. All rights reserved.