2011-04-13 57 views
0

好了,所以这是KernelHandler类需要帮助越来越像高(可能继承问题)

public class KernelHandler extends ImageHandler

我得到一个无法找到方法的getWidth()

我知道它有什么做继承,但我需要帮助,请

//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 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; 
    } 
+0

http://stackoverflow.com/questions/5651499/need-help-getting-height-of-image-possible-inheritance-problem看起来很相似 – 2011-04-13 15:42:32

+0

它(它是我的)我只是忘了登录,所以我无法发表评论或编辑 – 2011-04-13 15:44:12

+0

为了更好地提供帮助,请发布[SSCCE](http://pscode.org/sscce.html)。 – 2011-04-13 15:58:27

回答

0

getWidth()不应该在ImageHandler私有访问(或包专用访问,如果这两个类在不同的包)。你能检查一下吗?

简单地说,getWidth()应该以publicprotected作为前缀。

0

尝试改变myHand的类型的超类,这将是这样的:

ImageHandler myHand = new KernelHandler(nameOfImg);
+0

ImageHandler myHand = new KernelHandler(nameOfImg); – 2011-04-13 15:47:56

+0

我仍然无法找到getWidth()方法错误 – 2011-04-13 15:51:33

0

是否有一个名为的getWidth()在ImageHandler方法?我看到这个类的一些实现没有。这可能是它无法访问的另一个原因。

+0

imageHandler中没有一个。我可以在ImageHandler中创建一个基本上模仿BufferedImage的getWidth()吗? – 2011-04-13 15:50:59

+0

我想不出为什么你不应该能够。我不确定你使用的是哪一个版本,但是这是一个:http://www.hcilab.org/documents/tutorials/Brother/src/javadoc/core/doc/org/hcilab/btprinter/abstractionlayer/ImageHandler.html静态变量用于打印机支持的最大图像高度和最大图像宽度。我不确定这是否会对你有太大的帮助。你打算如何使用宽度和高度? – 2011-04-13 16:31:01