Java - nested class and array - Exception in thread "main"
java.lang.NullPointerException
I'm new to Java and I'm implementing a class (CenterTable) that contains a
nested class (CenterData). Inside the enclosing class, I want to create an
array of type CenterData. The code can be seen below:
public class CenterTable {
public class CenterData {
public int userId;
public double distance;
public double elevation;
public int point_00;
public int point_01;
public int point_10;
public int point_11;
public CenterData() {
userId = 0;
distance = 0;
elevation = 0;
point_00 = 0;
point_01 = 0;
point_10 = 0;
point_11 = 0;
}
} // end of CenterData class
public static CenterData[] centers = new CenterData[7064];
public static double centerMaxDistance = 0;
}
Whenever I try to access or set an element of the array centers:
CenterTable.centers[1].beam_user = 1;
System.out.println(CenterTable.centers[1].beam_user);
I get an error: Exception in thread "main" java.lang.NullPointerException
If I move the class CenterData out of CenterTable and into it's own java
class, I don't get an issue like that. I'm kind of stuck at this point, if
any one has any tips/hints that would be great.
Thanks in advanced!
No comments:
Post a Comment