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

2018/1/20

HELP ME! WHAT DOES THIS MEAN AND HOW DO I FIX IT!?

rory rory

2018/1/20

#
I need help with the line of code that reads: Sheep Sheep = (Sheep) getObjects(Sheep); getObjects(Sheep.class).get(0); an error message pops up that says "method getObjects in class greenfoot.World cannot be applied to the given types: required: java.lang.Class<A> found:Sheep reason; cannot infer type-variable(s) A (argument mismatch; Sheep cannot be converted to java.lang.class<A>) I DON'T UNDERSTAND WHAT IT MEANS

public class grassworld extends World
{
    /**
     * Create My world (grass). Our world has a size 
     * of 600x600 cells, where every cell is just 1 pixel.
     */
    public grassworld()
   {    
        super(900, 700, 1); 
   }
   {
      Snake snakey = (Snake) getObjects(Snake.class).get(0);
      if  (snakey.sheepsEaten > 0 )
      {
          showText("YOU LOSE!!!", 500,500);
          Greenfoot.playSound("Laugh.wav");
          Greenfoot.stop();
       }
       else
       {
           Sheep Sheep = (Sheep) getObjects(Sheep); getObjects(Sheep.class).get(0);
           int numFood = numberOfObjects() -2;
           if (numFood == 0)
               if (snakey.foodsEaten > Sheep.FoodsEaten)
               { 
                   showText("YOU LOSE!!!", 500,500);
                   Greenfoot.stop();
                }
                else if (snakey.foodsEaten < Sheep.FoodsEaten)
                {
                    showText("YOU WIN",500,500);
                    Greenfoot.playSound("Cheer.wav"); 
                    Greenfoot.stop();
                }
            }
        }
    }
attached is screenshot: file:///Users/20024/Desktop/Screen%20Shot%202018-01-19%20at%2011.16.37%20PM.png
xbLank xbLank

2018/1/20

#
rory wrote...
attached is screenshot: file:///Users/20024/Desktop/Screen%20Shot%202018-01-19%20at%2011.16.37%20PM.png
This says it all.
Super_Hippo Super_Hippo

2018/1/20

#
Compare line 12 with line 21. Maybe you can find your mistake yourself.
CxVercility CxVercility

2018/1/20

#
일리아스 wrote...
rory wrote...
attached is screenshot: file:///Users/20024/Desktop/Screen%20Shot%202018-01-19%20at%2011.16.37%20PM.png
This says it all.
Hahahahahahaha
rory rory

2018/1/20

#
Ok well that fixed that one error but now I have more errors :(
Yehuda Yehuda

2018/1/21

#
Are the "more errors" part of the same line of code? If yes, then say what they are. If you just have more errors in the project, then start a new discussion for the new topic.
You need to login to post a reply.