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:
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())); } }