My code might look weird. I just started learning. I want to store the values that are in the "person" object in the "icsClass" array. I keep getting this error.
Error: Exception in thread "main" java.lang.NullPointerException at com.company.Main.main(Main.java:74)
public static void main(String[] args) {
Student[] icsClass = new Student[MAX];
Scanner s = new Scanner(System.in);
int counter = 0;
int year;
int month;
int day;
System.out.println("This program will store 10 student's information.");
System.out.println("Do you want to continue? (Yes/No)");
String a = s.next();
if (a.equals("Yes") || a.equals("yes")) {
while (counter < MAX) {
Student person = new Student();
System.out.println("Please enter your first name:");
person.setfName(s.next());
System.out.println("Please enter your last name:");
person.setlName(s.next());
System.out.println("Please enter your year of birth:");
year = (s.nextInt());
while ((year < MIN_YEAR) || (year > MAX_YEAR)) {
System.out.println("Error: Year of birth must be between 1895 and 2021");
System.out.println("Please re-enter your year of birth:");
year = s.nextInt();
}
person.setYear(year);
System.out.println("Please enter your month of birth:");
month = (s.nextInt());
while ((month < MIN_MONTH) || (month > MAX_MONTH)) {
System.out.println("Error: Month of birth must be between 1 and 12");
System.out.println("Please re-enter your month of birth:");
month = s.nextInt();
}
person.setMonth(month);
System.out.println("Please enter your day of birth:");
day = s.nextInt();
while ((day < MIN_DAY) || (day > MAX_DAY)) {
System.out.println("Error: Day of birth must be between 1 and 31");
System.out.println("Please re-enter your day of birth:");
day = s.nextInt();
}
person.setDay(day);
counter = counter + 1;
if (counter == MAX) {
person.display();
System.out.println("Is the information above correct? (Yes/No)");
String b = s.next();
if ((Objects.equals(b, "Yes")) || (Objects.equals(b, "yes"))) {
icsClass[counter].setfName(person.getfName());
icsClass[counter].setlName(person.getlName());
icsClass[counter].setYear(person.getYear());
icsClass[counter].setDay(person.getDay());
icsClass[counter].setMonth(person.getMonth());
}
}
}
//for (int i = 0; i < MAX; i++) {
// icsClass[i].display();
//}
}
}
}