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

2014/7/11

Cannot find symbol

public class mass extends Mover
{
    /**
     * Act - do whatever the mass wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public mass()
    {
        vector v1 = new vector();
        v1.setLength(3);
        v1.setAngle(Math.PI/60);
    }

    public void act() 
    {
        setLocation(getX()+v1.getDx(), getY()+v1.getDy());
    } 
}
I get the error cannot find symbol - v1 when I try to compile. I'm using my own vector library which is based on the one made by CodingMath. How should I be creating vector v1? Please ignore my username.
danpost danpost

2014/7/11

#
The 'vector' object created on line 9 is local to the constructor of the class (only a valid reference up to line 12, where it is then eliminated -- flagged for garbage collection). If you move line 9 up to before line 7, then the 'mass' object will keep a reference to the 'vector' object. Please refer to the Java tutorial page on variables.
Thanks for the help. :)
You need to login to post a reply.