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

2012/7/31

NullpointerException with mouse

erdelf erdelf

2012/7/31

#
how can the following code result in an nullpointerexception
if(Greenfoot.mouseClicked(null))
{
     MouseInfo mouse = Greenfoot.getMouseInfo();  
     int button = mouse.getButton();   // the line with the error
}
davmac davmac

2012/7/31

#
This can happen if the mouse is clicked, and the mouse cursor is swiftly moved off the world before Greenfoot.mouseClicked(...) is called. You can check for a click (with Greenfoot.mouseClicked()) but you should not assume then that Greenfoot.getMouseInfo() will return non-null.
You need to login to post a reply.