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

2014/9/9

cannot find symbol -variable cl1

rakesh8015 rakesh8015

2014/9/9

#
import greenfoot.*; public class jaffa extends World { public jaffa() { super(600, 400, 1); class1 cl1=new class1(); addObject(cl1,50,100); class2 cl2=new class2(); addObject(cl2,200,200); class3 cl3=new class3(); addObject(cl3,100,40); System.out.println(cl1.x); } public class1 getjaffa() { return cl1; } }
rakesh8015 rakesh8015

2014/9/9

#
please help me. it is very important thanks in advance
Super_Hippo Super_Hippo

2014/9/9

#
cl1 is not saved permanently in the class. It is only used in the constructor and then, this reference is removed. Instead, save them outside the constructor:
public class jaffa extends World
{
    class1 cl1;
    class2 cl2;
    class3 cl3;
    public jaffa()
    {    
        super(600, 400, 1); 
        cl1=new class1();
        addObject(cl1,50,100);
        
         cl2=new class2();
         addObject(cl2,200,200);
         cl3=new class3();
         addObject(cl3,100,40);
         System.out.println(cl1.x);
    }
     public class1 getjaffa()
    {
        return cl1;
    }
}
What I suggest you to do is: Avoid using names that don't say anything! Class names also start with a capital letter.
rakesh8015 rakesh8015

2014/9/9

#
ohk thank you very much.. can you also solve the problem i just posted..please
danpost danpost

2014/9/9

#
rakesh8015 wrote...
ohk thank you very much.. can you also solve the problem i just posted..please
This was solved in the code given above (see lines 3 through 5 and lines 9, 12 and 14).
rakesh8015 rakesh8015

2014/9/9

#
i am talking about other problem not this one
You need to login to post a reply.