The goal is to fill an ArrayList with custom Country objects made up of information from a separate text file. The while loop gives me the "identifier expected" error, and I'm at my wit's end trying to fix it.
import java.util.Scanner;
import java.util.ArrayList;
import java.io.File;
import java.io.FileNotFoundException;
public class Driver {
public static void main(String[] args) {
//Instance variables
Scanner sc;
Country next = new Country();
String reader;
int size;
ArrayList<Country> ledger = new ArrayList<Country>();
//Suppressing this exception because I know it's there.
@SuppressWarnings("unreported exception FileNotFoundException; must be caught or declared to be thrown")
sc = new Scanner(new File("testLedger.txt"));
//"<identifier> expected" error
while (sc.hasNext()) {
next.setName(sc.nextLine());
next.setFaith(sc.nextLine());
next.setInfo(sc.nextLine());
next.setOrder(sc.nextInt());
ledger.add(next);
}
//Test accessor methods and filling of the ArrayList
for (int i = 0; i < ledger.size(); i++) {
System.out.println(ledger.get(i));
}
}
}