Why am I getting a NullPointerException with this code?
public static void main(String args[]) throws FileNotFoundException {
int i = 0;
Job[] job = new Job[100];
File f = new File("Jobs.txt");
Scanner input = new Scanner(f);
while (input.hasNextInt()) {
job[i].start = input.nextInt();
job[i].end = input.nextInt();
job[i].weight = input.nextInt();
i++;
}
}
I get the error at the very first line of the while loop on its very first run-through. I also have a separate class:
public class Job {
public int start, end, weight;
}
and the text file:
0 3 3
1 4 2
0 5 4
3 6 1
4 7 2
3 9 5
5 10 2
8 10 1
Thank you.