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

2012/10/27

cannot find symbol - method

bingbongman bingbongman

2012/10/27

#
Hello, I am a big newbie when it comes to programming and I've got a problem which I cant solve by myself.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot und MouseInfo)

/**
 * Beschreiben Sie hier die Klasse Bombe.
 * 
 * @author (Ihr Name) 
 * @version (Eine Versionsnummer oder ein Datum)
 */
public class Bombe extends Actor
{
    /**
     * Act - Tue was immer Bombe tun möchte. Diese Methode wird aufgerufen,
     * wenn die 'Act'- oder 'Run'-Knöpfe in der Umgebung gedrückt werden.
     */
    
    boolean clash = true;
    
    
    public void act() 
    {
        Actor Held = getOneIntersectingObject(Rakete.class);
        
        if(Held != null && clash == true)
        {
            clash = false;
            Greenfoot.playSound("crash.wav");
            Held.setCollisionCount();
            
        }
        else if(Held == null)
        {
            clash = true;  
        }
    }    
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot und MouseInfo)

/**
 * Beschreiben Sie hier die Klasse Rakete.
 * 
 * @author (Ihr Name) 
 * @version (Eine Versionsnummer oder ein Datum)
 */
public class Rakete extends Actor
{
    /**
     * Act - Tue was immer Rakete tun möchte. Diese Methode wird aufgerufen,
     * wenn die 'Act'- oder 'Run'-Knöpfe in der Umgebung gedrückt werden.
     */
    
    private int CollisionCount = 0;
    
    public void act() 
    {
        if( Greenfoot.isKeyDown("up") )
        {
            move(10);   
        }
        
        if( Greenfoot.isKeyDown("down") )
        {
            move(-10);
        }
        
        if( Greenfoot.isKeyDown("left") )
        {
            turn(-5);
        }
        
        if( Greenfoot.isKeyDown("right") )
        {
            turn(5);
        }
        
    }    
    
    public void setCollisionCount()
    {
        CollisionCount++;
    }
    
}
Everytime I try to compile the "Bombe.class" the error "cannot find symbol - method" pops up. The reason is in the line "Held.setCollisionCount();" , but I dont see it. I would really appreciate your help. Thanks! :)
danpost danpost

2012/10/27

#
The 'setCollisionCount' method is not an Actor class method (nor inherited from any super-class of Actor. In line 21 of the Bombe class you are declaring the variable 'Held' as an Actor class object (not a Rakete class object). Change line 21 to the following:
Rakete Held = (Rakete) getOneIntersectingObject(Rakete.class);
bingbongman bingbongman

2012/10/27

#
Thank you very much! :) I tried "Rakete Held = getOneIntersectingObject(Rakete.class); " before, but i forget to transform the Actor object into a Rakete object.
You need to login to post a reply.