开发者

Need help getting height of image (Possible Inheritance Problem)

开发者 https://www.devze.com 2023-02-24 18:21 出处:网络
Ok so this is the KernelHandler Class public class KernelHandler extends ImageHandler I\'m getting a cannot find method getWidth()

Ok so this is the KernelHandler Class

public class KernelHandler extends ImageHandler

I'm getting a cannot find method getWidth()

I know it has something to do with inheritance, but I need help, please

//Heres the contructor

 public KernelHandler(String nameOfFile)
{
   super(nameOfFile);


    }

// here's the super constructor
public ImageHandler(String  nameOfFile){


     URL imageURL = getClass().getClassLoader().getResource(nameOfFile);
    try
    {
     myImage = ImageIO.read(imageURL);
    }
    catch ( IOException e )
    {
        System.out.println( "image missing" );
    }

// Here's the method were trying to use

public static 开发者_Python百科int numOfRedBoxes(String nameOfImg)

    {
        KernelHandler myHand = new KernelHandler(nameOfImg);
        for(int i = 0; i < myHand.getWidth(); i++)

            for(int j = 0; j < myHand.getHeight(); j++){
                if(img.getRGB(i, j) == red){
                    numOfRedBoxes++;
               }   
            }
       }
      return numOfRedBoxes;
   }


getWidth() should not have private access in ImageHandler (or package private access if both classes are in different packages). Could you check that?

Simply put, getWidth() should be prefixed with public or protected.


Is there a method named getWidth() in ImageHandler? I have seen some implementations of this class that do not. That could be another reason why it is not accessible.


Try changing the type of myHand to that of the super class , it would be something like:

ImageHandler myHand = new KernelHandler(nameOfImg);
0

精彩评论

暂无评论...
验证码 换一张
取 消