Hey folks,
I am working on a getBalance method that retrieves a balance from a CSV file. I keep getting:
java.lang.NullPointerException
at java.util.StringTokenizer.<init>(StringTokenizer.java:182)
at java.util.StringTokenizer.<init>(StringTokenizer.java:204)
at atmEngine.getBalance(atmEngine.java:100)
at atmEngine.<init>(atmEngine.java:81)
at Launcher.main(Launcher.java:12)
I can't figure this one out! I threw in some console print outs to make sure it was getting the data correctly and it was outputting the following:
1111,25145.25
1111
2222,1200.12
2222
3333,99.52
3333
4444,1000000000
4444
null
which is all 100% correct (minus the null). In the CVS file there are Account Numbers (1111, 2222, etc) and then right after each account is the balance of that account.
Here is my code for the method.
public double getBalance(int accountNumber) throws IOException
{
String accountFile="accounts/accounts.csv";
double balance=-1.0;
int accountTranslation=0;
boolean accountVerified=false;
FileReader freader = new FileReader(accountFile);
BufferedReader outputFile = new BufferedReader(freader);
String str="404";
while((str!=null) || (accountTranslation==accountNumber))
{
str = outputFile.readLine();
System.out.println(str);
StringTokenizer strTokenizer = new StringTokenizer(str, ",");
accountTranslation = Integer.parseInt(strTokenizer.nextToken());
System.out.println(accountTranslation);
if(accountTranslation==accountNumber)
{
balance=Double.parseDouble(strTokenizer.nextToken());
accountVerified=true;
}
else
{
accountVerified=false;
}
}
if(!accountVerified)
JOptionPane.showMessageDialog(null, "Account does not exist");
return balance;
}
I'd give you all my code but theres about 1500 lines of it in a bunch of classes.
Anyway, all ideas are appreciated!
Thanks PO