This site requires JavaScript, please enable it in your browser!
Greenfoot back
TopInPut
TopInPut wrote ...

2011/12/10

Error:S

TopInPut TopInPut

2011/12/10

#
" method getOneObjectAtOffset() in class Actor.class cannot be applied to given types; " What that means? ;D
AwesomeNameGuy AwesomeNameGuy

2011/12/10

#
It means you need to cast it to the specific class. The method returns something that is in the "Actor" class, but most likely you are trying to assign it to a refrence to one of the subclasses of Actor. However, you solve this by casting it to the right type. Say your class is named "Foo" and is a subclass of actor. Then you would need to put in your code: Foo x = (Foo) getOneObjectAtOffset(Foo.class); and x is your reference variable.
TopInPut TopInPut

2011/12/10

#
 public void special() {
        TeamRot teamrot = getOneObjectAtOffset(TeamRot.class); //xOffset and yOffset can be whatever you want    
        if(TeamRot == null) { //if the player is not hitting an opposing team member  
      //then it can catch the ball,  
      tryToCatchBall();  
      //put the code to move the player here   
    }  
}  
public void tryToCatchBall()  
    {  
    Ball ball = (Ball) getOneIntersectingObject(this);  
    if(ball != null) {  
         //we divide the width and height by 2 to get the space between the center of the player and the edge of the player's image.  
         int width = getImage().getWidth()/2;  
         int height = getImage().getHeight()/2;  
         if(direction.equals("west"))  
            ball.setLocation(getX()-width, getY());  
         else if(direction.equals("north"))  
            ball.setLocation(getX(), getY()-height);  
         else if(direction.equals("east"))  
            ball.setLocation(getX()+width, getY());  
         else if(direction.equals("south"))  
            ball.setLocation(getX(), getY()+height);  
    }
}
That's the code i got in another Discuss. ;) But i tried it, and the error came. -.- Whats wrong? (It is in class TeamBlau, which is in class Player with TeamRot)
TopInPut TopInPut

2011/12/10

#
upps:) With
davmac davmac

2011/12/10

#
Actually, it means that the parameters you are passing to the method are the wrong type(s), or that you have the wrong number of parameters. Check the documentation and make sure that you understand what you need to pass to it and that your code provides the correct parameters. (In your code, how many do you give? How many are required?) Similarly for line 11: Ball ball = (Ball) getOneIntersectingObject(this); What is the required parameter type? What are you actually passing? (check the documentation).
You need to login to post a reply.