I created an array of 50 points, which I now want to fill with points ordered by their y coordinate in a 10x5 grid. I get a NullPointerException at if(i<5) P[i].x=0
. What am I doing wrong here?
Point[] P= new Point[50];
for (int i=0; i<P.length; i++) {
if (i<5) P[i].x=0;
else if (i<10) P[i].x=50;
else if (i<15) P[i].x=100;
else if (i<20) P[i].x=150;
else if (i<25) P[i].x=200;
else if (i<30) P[i].x=250;
else if (i<35) P[i].x=300;
else if (i<40) P[i].x=350;
else if (i<45) P[i].x=400;
else P[i].x=450;
if (i%5==0) P[i].y=0;
else if (i%5==1) P[i].y=50;
else if (i%5==2) P[i].y=100;
else if (i%5==3) P[i].y=150;
else P[i].y=200;
}