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


This is Static?

kiarocks kiarocks


Well my code says this
 public void color(Color color)<this is static?
and apparently it is a static method? Gives the error non static method cannot be referenced from static context if put in act method or here
kiarocks kiarocks


found the problem, was trying to access GreenfootImage class, not an image.
mjrb4 mjrb4


I know this is solved, but just to elaborate a bit - whenever you see that error message, it's generally because you're trying to do one of two things: - Call a non-static method (i.e. one that needs to be called on an object, not a class) from a class. This is what's happening above. It only makes sense to set the colour on one particular greenfoot image object, but there you haven't given an individual object, you've given a class. - Trying to call a non-static method directly from one that's static. The same principle applies, you're not currently "in the scope" of an object (being in a static method) therefore you can't sensibly pick what object to apply the method to.
You need to login to post a reply.