I know why, you used getKey(), but didn't look for getKey() to equal null. Assign getKey() to a variable, then in your if statement, write this: "if (key != null & key.equals("space"))".
@FlyingRabidUnicornPig:
I don't see any problem with the getKey method:
He wrote: 'Greenfoot.getKey() == "space"' and if getKey() returns 'null', this query will return false, because this only checks, whether this two inputs are the same!
He hasn't written 'Greenfoot.getKey().equals("space")', which would throw an error, when 'getKey()' returns 'null', because then, the compiler trys to run the method from an object, which don't exists. ;)
He wrote:
UserInfo.getMyInfo().getUserImage()
and sometimes, when you're not logged in or when there's a login-mistake, UserInfo.getMyInfo() returns 'null' and then an error occures! :)
About the getKey stuff, I think
if ("space".equals(Greenfoot.getKey())
is best, because the thing you check on is never null and is capable of being compared to something that is null. And I think
if (Greenfoot.getKey() == "space")
compares the pointers, because the 2 Strings are instances, not data types like integers, so this will always return false. But I may be wrong, because I can't run the scenario on this device and therefore don't know if it will work :)
In older Java-versions 'Greenfoot.getKey() == "space"' always returned wrong.
But in the current version, this will return true, if both strings are the same! :)
2013/10/6
2013/10/6
2013/10/6
2013/10/6
2013/10/6
2013/10/6
2013/10/6
2013/10/6
2013/10/6
2013/10/6
2013/10/6
2013/10/7
2013/10/7
2013/10/7
2013/10/8