I have no Idea why I always get a nullPointerException when I use this method.
"inv" is an array used for an inventory, first all fields are empty. The fields can be filled with different Items, Key is a subclass of Item.
The door only should open if there is a key in the inventory.
I would be happy if someone could help me :D.
Thanks
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | if (getOneObjectAtOffset(- 1 , 0 ,Door. class )!= null && Greenfoot.isKeyDown( "o" )) { Door door = (Door)getOneObjectAtOffset(- 1 , 0 ,Door. class ); for ( int i = 0 ; i< 8 ; i++) { Item a = inv.give(i); if (a.getClass() != null ) { if (a.getClass()==Key. class && door.open()== false ) { door.open(); } } } } |