So I've got a for as far as playing the game goes fully working boolean array that tracks if an item has been picked up already or not, but whenever I go to inspect on my "player" and click the entry of the array I get a nullpointer exception. I'm pretty sure this should be fixable.
The error report is as follows:
Exception in thread "Timer-46" java.lang.NullPointerException
at bluej.debugmgr.inspector.ObjectInspector.listElementSelected(ObjectInspector.java:413)
at bluej.debugmgr.inspector.Inspector.update(Inspector.java:337)
at greenfoot.gui.inspector.UpdateTask.run(UpdateTask.java:45)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
The code of the player that creates, calls and edits things in the array is the following. I am positive that the issue is not in the Pickup method because when I completely comment that out and inspect the player I get the same error, I added it regardless for completeness of code.
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 35 36 37 38 | public class Player extends Actor { //Declaring the array for tracking what items have been picked up as well as filling it with default false. boolean [] items = new boolean [] { false , false , false }; public void act() { //Calling all methods pickup(); //This method is to check if the player can see the item to be picked up. When it does it stores this in the array. public void pickup() { if (canSee(Apple. class )) { if (items[ 0 ] == false ) { Greenfoot.playSound( "item.wav" ); items[ 0 ] = true ; } } if (canSee(Ketchup. class )) { if (items[ 1 ] == false ) { Greenfoot.playSound( "item.wav" ); items[ 1 ] = true ; } } if (canSee(Cookie. class )) { if (items[ 2 ] == false ) { Greenfoot.playSound( "item.wav" ); items[ 2 ] = true ; } } } |