Hey, I'm trying to read string and integer info from a input txt file into an array. The string is the description of the food and the integer is how many are in stock in inventory.
I followed the example my teacher gave me but I'm getting an array out of bounds exception error for the bolded code line. It compiles everything alright but when I run it the error comes up. Any help would be appreciated, thanks.
Scanner inMenu = new Scanner (new FileReader("Menu.txt")); //assigns scanner to input file
//array for food description
int mSub = 0;
int maxSub = 0;
String  foodName = new String [maxSub];
foodName [mSub] = inMenu.next();
maxSub = mSub;
//array for food inventory
int mSub2 = 0;
int maxSub2 = 0;
int  foodInv = new int [maxSub2];
foodInv [mSub2] = inMenu.nextInt();
maxSub2 = mSub2;