EDIT: I misspelled the title.
I'm getting the following error
java.lang.NullPointerException
at The_World.mouse(The_World.java:86)
at The_World.questions(The_World.java:38)
at The_World.act(The_World.java:28)
at greenfoot.core.Simulation.actWorld(Simulation.java:513)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:456)
at greenfoot.core.Simulation.runContent(Simulation.java:204)
at greenfoot.core.Simulation.run(Simulation.java:194)
here is the code I'm using
Please help. I've been at this for a long time and I just cant seem to figure things out. I fix one problem and then 5 minutes later another problem comes up. its really frustrating. in my code where I'm getting the error all I'm trying to do is see if the mouse is clicked inside the specified rectangle. if it is set the value of the counter to 1 and if not then set the value to -1. 1 leads to the next question while -1 ends the game.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class The_World here. * * @author (your name) * @version (a version number or a date) */ public class The_World extends World { public static int counter = 0; int mousex; int mousey; /** * Constructor for objects of class The_World. * */ public The_World() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(600, 600, 1); } public void act() { questions(); } public void questions() { if (counter == -1) { clearWorld(); addObject(new Text("you lose"), 400, 400 ); mouse(); if (mousex >0 && mousey >0) { counter = 0; } } if (counter == 0) { clearWorld(); addObject(new Text("Click Circle"), 300, 50 ); addObject(new Shape(1,2,50,50,102,0,0,255 ), 109,402); //answer addObject(new Shape(0,2,70,50,102,0,153,255),119,232); addObject(new Shape(0,1,50,50,204,0,105,255),456,202); addObject(new Shape(0,1,70,50,51,0,205,255),433,400); if (Greenfoot.mouseClicked(null) ) { mouse(); if ( (mousex > 59 && mousex < 159)&& (mousey > 350 && mousey < 452) ) { counter = 1; } else { counter = -1; } } } if (counter == 1 ) { clearWorld(); } } public void clearWorld() { removeObjects(getObjects(null) ); } public void mouse() { { MouseInfo mouse = Greenfoot.getMouseInfo(); mousex = mouse.getX(); mousey = mouse.getY(); } } }