I want to set some data in array from objects, here is class A, it cause an NullPointerException. Why? how to solve this? what is the problem with my initializing?
class A {
int a;
public void setA(int a) {
this.a = a;
}
public class ObjArry {
public static void main(String[] args) {
A[] ObjectArray = new A[5];
ObjectArray[0].setA(10); //Exception occurs in this line
ObjectArray[1].setA(9);
ObjectArray[2].setA(8);
ObjectArray[3].setA(7);
ObjectArray[4].setA(6);
}