Pleaseee help me guys. I can't figure out why the elements in my array are null. I'm reading in from a file and take each line and saving it as a variable in the object and then adding the object to the array.
This is what I have so far...when i print out the array each element is null :/
Scanner fileIn=null;
try{
fileIn=new Scanner(new File("flights.txt"));
}catch(FileNotFoundException e){
System.out.print("Cannot find file.");
System.exit(-1);
}
int count=0;
while(fileIn.hasNext()) {
fileIn.nextLine();
count++;
}
listFlights=new Flight[count/3];
num=listFlights.length;
int i=0;
String d;
String n;
int h;
int m;
while(fileIn.hasNextLine()){
i++;
n=fileIn.nextLine();
d=fileIn.nextLine();
h=fileIn.nextInt();
m=fileIn.nextInt();
System.out.print(i);
Time time=new Time(h, m);
listFlights[i]=new Flight(n, d, time);
}
The file looks like
Fli815
The_Island
8 15
UA302Y
Chinle
8 14
TI2745
Ganado
14 22
DL762A
Dinne
2 45