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

2012/4/6

static

tylers tylers

2012/4/6

#
hi, im getting an error for this code
 mX =  MouseInfo.getX();
mY =  MouseInfo.getY();
the error is: non-static method getY() cannot be referenced from a static context. help
kiarocks kiarocks

2012/4/6

#
You need a variable of mouse info to call getY() and getX(),
MouseInfo mouse = Greenfoot.getMouseInfo();
mX = mouse.getX();
y = mouse.getY();
ttamasu ttamasu

2012/4/6

#
My guess is that your method must be declared a static method. A static mathod requires that varibles and methods used are also static. mouse.getX() is not static. The simple solution if this is the case is delete the word static from your method signature. eg. public static void myMethod() to public void myMethod() cheers Takashi
tylers tylers

2012/4/6

#
thanks it works now
You need to login to post a reply.