I used to write my program codes in C and now moving to Java trying to define a simple struct and create and array of it in the code below, however the run-time exception occurs Exception in thread "main" java.lang.NullPointerException at CPoint.main(CPoint.java:19) I know i have to allocate memory to my array somewhere, but do not know where. Any help will be appreciated:
public class CPoint {
public int x;
public int y;
public CPoint(int size){
System.out.println("Constructor1 is called");
}
public CPoint(){
System.out.println("Constructor2 is called");
}
public static void main(String[] args){
CPoint [] p = new CPoint [3];
p[0].x=90;p[0].y=80; // this is line 19
System.out.println(p[0].x);
}
}
PS. I would like to allocate memory somewhere in the class CPoint , not in main, if possible I would like to keep the main() code as simple as possible