返回值时不兼容的类型 [英] Incompatible types when returning value
问题描述
我希望在地图上显示带有绘制线条的图像,并为图像中的每个部分创建单独的图像(多条连接线条)。我写了这段代码:
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:
public BufferedImage getLineImage() {
BufferedImage lineImage = null;
BufferedImage lineImage1[]=null;
int i=0;
if(image != null) {
lineImage1[i] = new BufferedImage(image.getWidth(), image.getHeight(), image.getType());
lineImage = new BufferedImage(image.getWidth(), image.getHeight(), image.getType());
Graphics2D g1 = lineImage1[i].createGraphics();
Graphics2D g = lineImage.createGraphics();
g.setColor(Color.WHITE);
g.setStroke(new BasicStroke(5, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
g1.setColor(Color.WHITE);
g1.setStroke(new BasicStroke(5, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
for(Section section : observeTraffic) {
section.paintTags(g1);
i++;
}
for(Section section : observeTraffic) {
section.paintTags(g);
}
}
return lineImage;
return lineImage1;
}
但在最后一行我收到错误:不兼容的类型
but in the last row I get error: Incompatible types
java:不兼容类型
required:java.awt.image.BufferedImage
found:java.awt.image.BufferedImage []
java: incompatible types required: java.awt.image.BufferedImage found: java.awt.image.BufferedImage[]
有人可以帮帮我吗?
谢谢
推荐答案
lineImage1
定义为 BufferedImage lineImage1 []
,这是一个BufferedImages数组。该方法的返回值是 BufferedImage
。
lineImage1
is defined as BufferedImage lineImage1[]
, which is an array of BufferedImages. The return value of the method is BufferedImage
.
您要么将返回类型更改为 BufferedImage
s,或只返回一个 BufferedImage
。
You either want to change the return type to an array of BufferedImage
s, or only return a single BufferedImage
.
这篇关于返回值时不兼容的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!