So this is my main class, am basically trying to read from a txt file a list of items and am trying to store them in an arraylist of multiple objects but for some reason I keep getting an inputmissmatch error if I tried to have multiple lines in the txt file and multiple objects, however let's say I have a txt that has one line & I add one object to the list, it works perfectly fine
public static void main(String[] args) throws FileNotFoundException, IOException {
// FileReader fr = new FileReader("Item2.txt");
Scanner file = new Scanner(new File("item.txt"));
ArrayList<Item> List = new ArrayList<Item>();
List.add(new ClothingItem(file.next().charAt(0), file.next(), file.next(), file.nextInt(), file.next(), file.nextDouble(), file.nextInt()));
List.add(new ClothingItem(file.next().charAt(0), file.next(), file.next(), file.nextInt(), file.next(), file.nextDouble(), file.nextInt()));
List.add(new Computer(file.nextInt(), file.next(), file.nextDouble(), file.nextInt(), file.next(), file.next(), file.next(), file.nextDouble(), file.nextDouble()));
List.add(new FoodItem(file.nextDouble(), file.next(), file.nextInt(), file.next(), file.nextDouble(), file.nextInt()));
List.add(new FoodItem(file.nextDouble(), file.next(), file.nextInt(), file.next(), file.nextDouble(), file.nextInt()));
List.add(new Beverages(file.nextInt(), file.next(), file.nextInt(), file.next(), file.nextDouble(), file.nextInt()));
ClothingItem[] list1 = List.toArray(new ClothingItem[List.size()]);
ClothingItem[] list2 = List.toArray(new ClothingItem[List.size()]);
Computer[] list3 = List.toArray(new Computer[List.size()]);
FoodItem[] list4 = List.toArray(new FoodItem[List.size()]);
FoodItem[] list5 = List.toArray(new FoodItem[List.size()]);
Beverages[] list6 = List.toArray(new Beverages[List.size()]);
for (Item A : List) {
System.out.println(A);
}
}
}
File that am trying to read
M RED MALE 1001 Shirt 19.0 100
L BLACK FEMALE 1002 Shoes 49.0 25
1003 Thinkpad 1050.0 2 Samsung i710610U SMEF 8.0 512.0
5.0 NotFresh 1004 GreenPeas 3.0 117
5.0 Fresh 1005 Lettuce 2.0 90
1006 NotAlcholic 1981 Cola 3.0 50