And apparently I keep getting this nullpointer exception:
Here's the pertinent code:
The CheckHitBox code-
The act code:
java.lang.NullPointerException at Iron.checkHitBox(Iron.java:133) at Iron.act(Iron.java:56) at greenfoot.core.Simulation.actActor(Simulation.java:594) at greenfoot.core.Simulation.runOneLoop(Simulation.java:552) at greenfoot.core.Simulation.runContent(Simulation.java:215) at greenfoot.core.Simulation.run(Simulation.java:205)
/** * Making sure the mouse is within the bounds of the ore. */ private boolean checkHitBox(){ MouseInfo mouse = Greenfoot.getMouseInfo(); if(ore < 11){ return false; } if( mouse.getX() >= this.getX() && mouse.getY() >= this.getY() && mouse.getX() <= this.getX()+SIZE && mouse.getY() <= this.getY()+SIZE ){ return true; }else{ return false; } }
/** * Tell us how much ore is left in this vein. */ public void act(){ MouseInfo mouse = Greenfoot.getMouseInfo(); String oreDisp; if(ore > 999){ oreDisp = String.format("%.02f",(ore/1000)) + "k"; }else{ oreDisp = Integer.toString((int) ore); } if (checkHitBox() && info == null) { info = new Label("\n Iron: " + oreDisp + " \n ", 24); getWorld().addObject(info, mouse.getX(), mouse.getY()-20); } else if (checkHitBox() == false) { getWorld().removeObject(info); info = null; }else if (Greenfoot.isKeyDown("f") && checkHitBox()){ getWorld().removeObject(info); info = null; info = new Label("\n Iron: " + oreDisp + " \n ", 24); getWorld().addObject(info, mouse.getX(), mouse.getY()-20); } }