So I'm trying to use the drawLine in my world subclass, called Ground. But when I compile it I get an error saying
non-static method getBackground() cannot be referenced from a static context
This is my code for Ground:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Color; /** * Write a description of class Ground here. * * @author (your name) * @version (a version number or a date) */ public class Ground extends World { public static final int CELL_SIZE = 20 ; /** * Constructor for objects of class Ground. * */ public Ground() { // Create a new world with 800x600 cells with a cell size of 1x1 pixels. super ( 40 , 30 , 20 , false ); start(); drawLine(); } public void drawLine() { Ground.getBackground().drawLine( 10 , 2 , 10 , 20 ); } public void start() { Food food = new Food(); addObject(food, Greenfoot.getRandomNumber(getWidth()), Greenfoot.getRandomNumber(getHeight())); Worm worm = new Worm(); addObject(worm, Greenfoot.getRandomNumber(getWidth()), Greenfoot.getRandomNumber(getHeight())); } } |