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

2014/7/8

I am not able to get any information from the mouse

sengst sengst

2014/7/8

#
I need help getting information from the mouse like the mouse's X and Y coordinates. I can get the code to compile, but when it runs I get a nullPointerExeption error message. Can anyone help me? Thanks.
danpost danpost

2014/7/8

#
'Greenfoot.getMouseInfo()' will return 'null' unless some mouse action has been registered (movement, button press or release, etc). So, before trying any MouseInfo methods on the object, make sure that it is not 'null':
MouseInfo mouse = Greenfoot.getMouseInfo();
if (mouse != null)
{
    int mouseX = mouse.getX();
    int mouseY = mouse.getY();
    // etc.
}
sengst sengst

2014/7/8

#
Thanks. I'll give it a try.
sengst sengst

2014/7/8

#
It worked! Thanks again!
You need to login to post a reply.