0

所以我得到了这个错误:

java cannot be applied to given types; required: java.lang.String,int,int; found:java.lang.String; reason: actual and formal argument lists differ in lenghhs

当我在一个演员中输入这个时(我使用 Greenfoot):

 public String getPunkte()
{
    String stringPunkte = Integer.toString(punkte);
    return(stringPunkte);
}

这在另一个:

public void malePunkte()
{
    GreenfootImage img = new GreenfootImage(50, 10);
    img.drawString(getPunkte());

}

对于那些不明白的人:这应该将 int(punkte)(德语中的点)转换为字符串,然后将一个演员的点数返回给另一个演员,然后显示该数字。

如果您仍然不明白或者您需要另一段代码,请询问。

谢谢

4

1 回答 1

5

好吧,错误是不言自明的,不是吗?

你期望得到的是String, int, int,你只“供应”String

尝试这个

public void malePunkte() {
    GreenfootImage img = new GreenfootImage();
    img.drawString(getPunkte(), 50, 10);
}

附言。在 return 语句中,您不需要用括号括起来要返回的变量。做就是了

return stringpunkte

附言。我不知道 GreenfootImage 是什么 ;)

编辑:根据提供的有用链接 - Gyro Gearless

www.greenfoot.org/files/javadoc/greenfoot/GreenfootImage.html

drawImage(GreenfootImage image, int x, int y) 
     Draws the given Image onto this image

GreenfootImage(int width, int height) 
      Create an empty (transparent) image with the specified size.

如您所见,drawImage 绘制在创建的“空”图像之上。因此,作为构造函数参数,您可以指定空图像的大小,而对于方法,您可以指定将在空图像之上的新图像的大小

于 2014-04-03T15:04:34.713 回答