Question

so i got this error:

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

when i typed this in one Actor (im using Greenfoot):

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

and this in the other:

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

}

for those who dont understand: this is supposed to convert the int (punkte)(means points in german) into a String and then return the amount of points in one actor to the other, wich then displays that number.

if you still don't understand or you need another piece of code just ask.

Thx

Was it helpful?

Solution

Well error is quite self explanatory isn't it ?

what you expect to get back is String, int, int and you only 'supply' String

try this

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

ps. on return statement you do not need to surround with bracket the variable you want to return. Just do

return stringpunkte

ps. i have no idea what the GreenfootImage is ;)

edit: According to helpful link provided by - Gyro Gearless

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

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

and

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

As you can see drawImage draws on top of the created 'empty' image. So as Constructor argument you can specify the size of empty image, and as to a method you can specify the size of the new image that will go on top of the empty one

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top