I'm having problems reading in my file into an array of objects. I created an if statement so that the lines of data get separated into two different subgroups one is produce and the other is cleaning. But when I run the program the objects that are created are empty. How do I connect the file into the objects? I'm missing something crucial.
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
public class Inventory{
public static void main(String[] args){
int i=0;
Product[] pr=new Product[16];
File InventoryFile=new File("inventory.csv");
Scanner in=null;
try{
in=new Scanner(InventoryFile);
while(in.hasNext()){
String line=in.nextLine();
String[]fields=line.split(",");
if(fields[0].equals("produce"))
pr[i]= new Produce();
else
pr[i]=new Cleaning();
i++;
}
System.out.println(pr[6]);
}catch(FileNotFoundException e){
System.out.println("Arrgggg"+e.getMessage());
}
}
}