So I'm having an issue with my array returning with a bunch of nulls even though I have the if statement not allowing the SoftballPlayer obj if it != null....and my array is bounded by 24 so it works for the larger files but still returns nulls if the file input is less than my max of 24? [MAX_PLAYERS = 24 MAX_EXCLUDED = 30]
public int getPlayerCount() {
return playerCount;
}
public void setPlayerCount(int playerCountIn) {
playerCount = playerCountIn;
}
public void playerReadFile(String fileNameIn) throws IOException {
Scanner scanFile = new Scanner(new File(fileNameIn));
teamName = "";
String number = "";
String name = "";
String position = "";
double specializationFactor = 0.0;
double battingAvg = 0.0;
double outfielderFieldingAvg = 0.0;
double infielderFieldingAvg = 0.0;
int wins = 0;
int losses = 0;
double era = 0.0;
int saves = 0;
teamName = scanFile.nextLine();
while (scanFile.hasNext()) {
String playerLine = scanFile.nextLine();
Scanner scan = new Scanner(playerLine);
scan.useDelimiter(",");
char i = scan.next().charAt(0);
number = scan.next();
name = scan.next();
position = scan.next();
specializationFactor = Double.parseDouble(scan.next());
battingAvg = Double.parseDouble(scan.next());
if (playerCount < MAX_PLAYERS) {
switch (i) {
case 'O':
outfielderFieldingAvg = Double.parseDouble(scan.next());
Outfielder out = new Outfielder(number, name, position,
specializationFactor, battingAvg, outfielderFieldingAvg);
if (out != null) {
roster[playerCount] = out;
playerCount++;
}
break;
case 'I':
infielderFieldingAvg = Double.parseDouble(scan.next());
Infielder inf = new Infielder(number, name, position,
specializationFactor, battingAvg, infielderFieldingAvg);
if (inf != null) {
roster[playerCount] = inf;
playerCount++;
}
break;
case 'P':
wins = Integer.parseInt(scan.next());
losses = Integer.parseInt(scan.next());
era = Double.parseDouble(scan.next());
Pitcher pit = new Pitcher(number, name, position,
specializationFactor, battingAvg, wins,
losses, era);
if (pit != null) {
roster[playerCount] = pit;
playerCount++;
}
break;
case 'R':
wins = Integer.parseInt(scan.next());
losses = Integer.parseInt(scan.next());
era = Double.parseDouble(scan.next());
saves = Integer.parseInt(scan.next());
ReliefPitcher rpit = new ReliefPitcher(number, name, position,
specializationFactor, battingAvg, wins,
losses, era, saves);
if (rpit != null) {
roster[playerCount] = rpit;
playerCount++;
}
break;
default:
if (excludedCount < MAX_EXCLUDED) {
excludedRecords[excludedCount] = playerLine;
excludedCount++;
}
break;
}
}
else if (excludedCount < MAX_EXCLUDED) {
excludedRecords[excludedCount] = playerLine;
excludedCount++;
}
}
}