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


1 2 3 4 5 6 7 8 9 | String key = Greenfoot.getKey(); if (key != null ) { if (key.length() == 1 && ( char ) 127 == key.charAt( 0 )) { // do delete action here } // check other keys here } |
1 2 3 4 5 6 7 8 9 10 11 12 | 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 ; } |
1 2 | Object a = null ; a.dosomething(); // exception |
1 2 3 4 5 | if (pw == null ) System.out.println( "pw is null" ); if (pw.p1Left == null ) System.out.println( "pw1Left is null" ); // etc. |