Need help getting height of image (Possible Inheritance Problem)
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);
精彩评论