This site requires JavaScript, please enable it in your browser!
Greenfoot back
Tuckerbm
Tuckerbm wrote ...

2017/3/7

How do I fix this Error message?

Tuckerbm Tuckerbm

2017/3/7

#
public void collide() { if(isTouching(Enemy.class)) { Space.Loselife(); removeTouching(Enemy.class); } if(isTouching(EBullet.class)) { Space.Loselife(); removeTouching(EBullet.class); } } non-static method cannot be referenced from a static context
Nosson1459 Nosson1459

2017/3/7

#
You have to do getWorld().Loselife; but I don't know if this will fix the problem, if it doesn't then show the full class code - top to bottom.
danpost danpost

2017/3/7

#
A class is capable of creating multiple objects of the same type and therefore 'Space' is not specific enough to indicate which world will execute 'Loselife'. Using 'getWorld' will return the correct World object to execute the method on; however that is still not enough because it does not specifically return a Space object which is necessary to execute the method located in that class. We must inform the system that it is indeed a Space object through typecasting:
((Space)getWorld().Loselife();
You need to login to post a reply.