I'm trying to read some data out of a file, and then plug that into a Currency constructor and a couple other variables, but I'm getting errors. The relevant section of code:
public Bank(String fileName) {
Scanner fileReader = new Scanner(fileName);
bankName = fileReader.nextLine();
commissionRate = fileReader.nextDouble();
//setup each currency
currency1 = new Currency(fileReader.next(), fileReader.nextDouble());
currency2 = new Currency(fileReader.next(), fileReader.nextDouble());
currency3 = new Currency(fileReader.next(), fileReader.nextDouble());
}
Here's the error:
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextDouble(Unknown Source)
at project3.Bank.<init>(Bank.java:16)
Some googling tells me this means its not able to read the file correctly. It works up to the bankName = fileReader.nextLine()
part, but everything after that fails. And I can't see why its not able to find the next whatever, since the files its supposed to read look something like this:
First Fake Bank
1.1
MXN 1.1
EUR 1.2
JPY 118.7
The structure is one line of string, then a double under that, then three lines with a string followed by a double.