I'm new to Java, here's my code so far:
public static MyPoint[] generatePoints(int num) {
MyPoint[] arr = new MyPoint[num];
for (int i = 0; i < num; i++) {
arr[i].x = 1;
arr[i].y = 1;
}
return arr;
}
class MyPoint {
int x;
int y;
}
Error:
java.lang.NullPointerException: Cannot assign field "x" because "arr[i]" is null
How can I fix this? What I want is an array of points.