Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
800 views
in Technique[技术] by (71.8m points)

java - How do I fix "cannot resolve method"?

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;
}

And then this class:

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;
    }
}

I have two questions:

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...