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

2019/6/4

Non static method cannot be referenced from a static context

jrome jrome

2019/6/4

#
If anybody could help with this it would be great. I'm trying to call a method from my world in an actor class and it keeps bringing up this error.
Super_Hippo Super_Hippo

2019/6/4

#
"static" can be translated with "belonging to a class". Static variables are shared with all members of the same class. If every object of the same class has its own value for the variable, it can't be static. It is basically the same for methods. Methods can be static when they don't use anything non-static. For example a method like "getX()" is not static, so you can not use "ClassName.getX()". An Actor is in the world and has its X-coordinate. If there are several Actors of this class in the world, each of them wants to move separately. To use a non-static method, you need to call the method on the object and not on its class. So you will need a reference to the object first. You can save one when creating the object or get it in different ways depending on what exactly you are doing.
You need to login to post a reply.