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

2011/11/6

About the Class MouseInfo

Upupzealot Upupzealot

2011/11/6

#
int x = Greenfoot.getMouseInfo().getX(); what's run with this sentence? compiler told "java.lang.NullPointerException"
Upupzealot Upupzealot

2011/11/6

#
MouseInfo mouse = Greenfoot.getMouseInfo(); int x = mouse.getX(); Still Wrong
mik mik

2011/11/6

#
Greenfoot.getMouseInfo() can return null. When it does, your 'mouse' variable will contain null, and then mouse.getX() fails with a NullPointerException, because you have no 'mouse' object. In general, you should call getMouseInfo after a mouse event, such as mouseClicked.
Upupzealot Upupzealot

2011/11/6

#
mik wrote...
Greenfoot.getMouseInfo() can return null. When it does, your 'mouse' variable will contain null, and then mouse.getX() fails with a NullPointerException, because you have no 'mouse' object. In general, you should call getMouseInfo after a mouse event, such as mouseClicked.
Thank you! Now I undersdand! Another question about mouse event, how can I find out if the mouse is hold on sth. I tried to figgure it out by getX() and getY(),is there some good iead?Thanks
You need to login to post a reply.