@gusbus123 Danpost's tip gives an exception, because key is null.


String key = Greenfoot.getKey(); if (key != null) { if (key.length() == 1 && (char) 127 == key.charAt(0)) { // do delete action here } // check other keys here }
Pacman pw = (Pacman) getWorld(); String i=""; switch(ID) { case 3: i=pw.p1Left; break; case 4: i=pw.p1Right; break; case 5: i=pw.p1Up; break; case 6: i=pw.p1Down; break; case 7: i=pw.p2Left; break; case 8: i=pw.p2Right; break; case 9: i=pw.p2Up; break; case 10: i=pw.p2Down; break; }
Object a = null; a.dosomething(); // exception
if (pw == null) System.out.println("pw is null"); if (pw.p1Left == null) System.out.println("pw1Left is null"); // etc.