Incompatible types when returning value

后端 未结 3 1958
野的像风
野的像风 2021-01-26 11:15

I want to display an image with drawn lines on a map, and separate images made for every single section in the image (several connected lines). I have written this code:

相关标签:
3条回答
  • 2021-01-26 11:51

    Return type of the method is BufferedImage
    But you try to return array of BufferedImage. That is thy the error occurs.
    BTW: do you really have 2 return statements?

    0 讨论(0)
  • 2021-01-26 11:52

    some people may find confusing when they don't know that

    BufferedImage lineImage1[] = null;
    

    is the same as

    BufferedImage[] lineImage1 = null;
    

    and you cannot have two returns, it's illegal in Java.

    So if you want to return more than one object, you can do something like

    public Object[] getLineImage() {
    (...)
        Object[] o = new Object[2];
        o[0]=lineImage;
        o[1]=lineImage1;
        return o;
    }
    
    0 讨论(0)
  • 2021-01-26 12:03

    lineImage1 is defined as BufferedImage lineImage1[], which is an array of BufferedImages. The return value of the method is BufferedImage.

    You either want to change the return type to an array of BufferedImages, or only return a single BufferedImage.

    0 讨论(0)
提交回复
热议问题