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

2015/12/15

Illegal start of expression: private int

jalaw02 jalaw02

2015/12/15

#
Hi. I am having a problem which I cannot figure out. I am receiving an error 'Illegal start of expression' at the beginning of a certain bit of code:
public void hide()
    {
        private int timer = 50;      
        {
              if (timer > 0)
             {

                   timer --;
        
                   if (timer == 0)
        
                   {
        
                        getWorld().removeObject(this);
        
                        timer = 50;
        
                   }
        
              }
        
        }
     }
Sorry, I'm very new to this kind of stuff. If anyone could let me know what the problem is? Thanks.
Super_Hippo Super_Hippo

2015/12/15

#
Place line 3 outside the method. Private/public/protected is used to give access (to this method or variable) to certain classes. Using it inside a method doesn't make any sense, so you can't do that.
jalaw02 jalaw02

2015/12/21

#
Thanks. Much appreciated!
You need to login to post a reply.