save mouse clicks in java
<p>I am trying to save the location of the mouse position-on a click.Then i need to analyze its motion to do a specific task.I used the mouseListener interface and when the user clicks the mouse i add the point of clicking to a point array.Then when a user clicks on a button,i tried loop through the array to analyze the motion but i get a null pointer exception at <code>if(points[i].x&lt;points[i+1].x)</code>
Here is the code </p>

<pre><code>Point points[] = new Point[2000];
int numPoints = 0;
void eventOutput(String eventDescription, MouseEvent e) {
  System.out.println(eventDescription+" X= "+e.getX()+" Y= "+e.getY());
  //xList.add(new Integer(e.getX()));
  //yList.add(new Integer(e.getY()));
  points[numPoints] = new Point(e.getX(), e.getY());
  ++numPoints;        
}
for(int i=0;i&lt;points.length;i++)
{
  System.out.println("In MOO "+points[i].x);
  if(points[i].x&lt;points[i+1].x)
  {
    xInc=true;
    if(points[i].y&lt;points[i+1].y)
    {
      yInc=true;
    }
    else if(points[i].y&gt;points[i+1].y)
    {
      yDec=true;
    }
  }
  else if(points[i].x&gt;points[i+1].x)
  {
    xDec=true;
    if(points[i].y&lt;points[i+1].y)
    {
      yInc=true;
    }
    else if(points[i].y&gt;points[i+1].y)
    {
      yDec=true;
    }}}}
</code></pre>

<p>Could anyone please help me about that.Thanks in advance</p>
