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

2012/2/11

Reached end of file while parsing error

lindalubina lindalubina

2012/2/11

#
Hi, I'm just starting with Greenfoot and am on the crab scenario. I have copied the code and compared it several times with the one in the tutorial - they seem to be exactly the same - yet I'm getting the error message 'reached end of file while parsing'. What can I try to resolve this, please?
lindalubina lindalubina

2012/2/11

#
Me again! I thought it might help if I show my code: import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) public class Crab extends Actor { /** * Act - do whatever the Crab wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { move(4); if (Greenfoot.isKeyDown("left")) { turn(-3); } if (Greenfoot.isKeyDown("right")) { turn(3); } } I tried to do a screenshot but it didn't want to paste. I see others have done this ... how? Thanks to anyone who can help.
danpost danpost

2012/2/11

#
If you indent everything from the /** down to the end, you will see that the last } is missing. I have trouble with using the text modifiers below the posting editor. I just put before the code and after the code (putting them together here would be a mistake).
lindalubina lindalubina

2012/2/11

#
Thanks very much. I eventually figured out that it was the bottom curly bracket that was missing. The top curly bracket is not shown in the tutorial screen shot ... so I had to use my brain to think it through. Probably the best way to learn!
danpost danpost

2012/2/11

#
Usually is! Good job.
lindalubina lindalubina

2012/2/12

#
Back again! I now have a problem with ';' expected. This is highlighted to happen after public void eat(), but if I put it in, I get missing method body, or declare abstract. I don't understand this and there is no semi colon shown here in the tutorial. Could you help, please? I have pasted the code below: { /** * Act - do whatever the Crab wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { moveAndTurn(); eat(); } public void moveAndTurn() { move(4); if (Greenfoot.isKeyDown("left")) { turn(-3); } if (Greenfoot.isKeyDown("right")) { turn(3); } } public void eat() }
lindalubina lindalubina

2012/2/12

#
Sorry! I'm posting before I think them through!! I realised that the tutorial spelled out what was needed for the first part (moveAndTurn) but not for eat. I have now copied the same format for eat and it's working fine. Thanks if you have tried to help me.
You need to login to post a reply.