In my program with the for loop, it works perfectly, without errors, but when I remove the for loop and manually increment it because I only want to input once and store in array, there's a NullPointerException. It looks the same for me, the only difference is it doesn't loop, but instead increment it manually. How can I fix it?
public class Javaapp {
public static void main(String[] args) {
Team competitive = new Team ("Cloud9", 5, 14, 18);
Member [] member = new Member [5];
Scanner input = new Scanner(System.in);
int answer = input.nextInt();
for(int i=0; i<competitive.maxMember; i++){
System.out.printf("Name:");
String tmpName = input.next();
System.out.printf("Age:");
int tmpAge = input.nextInt();
member[i] = new Member(tmpName, tmpAge);
}
for(Member m: member){
if (competitive.checkQualification(m) == true){
competitive.addMember(m);
System.out.println("You're officially part of the team");
}
else if (competitive.checkQualification(m) == false)
System.out.println("You did not meet the requirements");
}
}
}