如何解决“无法解析方法"? [英] How do I fix "cannot resolve method"?

查看:583
本文介绍了如何解决“无法解析方法"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以首先我要上这个课:

So first I have this class:

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

1) Why do I don't need to create an instance of the class Image. Here I can already use filtered.setPixels...

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

2) How do I fix the Problem with "cannot resolve method"?

推荐答案

我真的无法从您的帖子中看出来,因为您发布的第一个代码段似乎不是一个完整的类,而是一部分.我假设您有一个Image类,并且该Image类有一个名为getHeight()的方法.

I can't really tell from your post because the first snippet you've posted doesn't seem to be an entire class but rather a portion of it. I assume you have an Image class, and that Image class has a method called getHeight().

在for循环条件for (int i = 0; i < getHeight(); i++)中,您很可能希望将getHeight()更改为filtered.getHeight(),因为getHeight()Image类内部的方法,而filtered是(大概)类型为Image.

Inside the for loop condition for (int i = 0; i < getHeight(); i++), you'll most likely want to change getHeight() to filtered.getHeight() because getHeight() is a method inside of the Image class, and filtered is (presumably) of type Image.

这篇关于如何解决“无法解析方法"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆