Java again....

Associate
Joined
6 Dec 2007
Posts
2,103
Hey all (again), this time I was trying to write a piece of code to sort some details, and a line in particular keeps throwinb up a NullPointerException, and I can't figure out why. My head hurts.

public void sortAccountDetails()
{
int iAccountNumber;

for (int i3 = 0; i3 < accountDetails.length -1; i3++)
{
int minPos = i3;
for ( int j3 = i3 +1; j3 < accountDetails.length; j3++ )
{
iAccountNumber = Integer.parseInt( accountDetails [ j3 ].getAccountNumber() );


if ( iAccountNumber < Integer.parseInt( accountDetails [ j3 ].getAccountNumber()))
{
minPos = j3;
}//end if
}//end for

The bold bit is giving me jip. It's not the parseInt doing funny things to my array is it? Thanks
 
Ok, sorry, basically the array contains details that are read in from a text file, details are:

12345678
T Jowell
270.50

34781234
T Blair
100.00

11112222
J Bloggs
250.00

44448888
L Hamilton
1200.00

22228888
G Brown
150.00

********

With the asterisks as a terminator.

So, as far as I can see it shouldn't be null, but that's what its giving me...
 
Ok, this bit is the bit that reads in the info from the text file into an array:

public void loadAccountDetails( String filename ) throws IOException
{

String anAccountNumber;
String anAccountName;
double aBalance;
String textFilesPath = "H:/";
BufferedReader accountsFileIn = Text.open(textFilesPath + filename);

activeAccounts = 0;
anAccountNumber = Text.readString(accountsFileIn);
while (anAccountNumber.compareTo("********") != 0 && false && activeAccounts < MAX_ACCOUNTS)
{
anAccountName = Text.readLine(accountsFileIn);
aBalance = Text.readDouble(accountsFileIn);

accountDetails [activeAccounts] = new BankAccount(anAccountNumber, anAccountName, aBalance);
activeAccounts++;
anAccountNumber = Text.readLine(accountsFileIn);
}

accountsFileIn.close();

I'm not too sure where I've gone wrong, but its driving me nuts! Java n00b here lol. Thanks for any help you can give me!

Edit: all getAccountNumber does is return accountNumber
 
Last edited:
I've changed the read-in code to the following, but I still get the same exception. I must be doing something wrong! LOL

activeAccounts = 0;
anAccountNumber = Text.readString(accountsFileIn);
while (anAccountNumber.compareTo("********") != 0 && false && activeAccounts < MAX_ACCOUNTS)
{
anAccountName = Text.readLine(accountsFileIn);
aBalance = Text.readDouble(accountsFileIn);

if (accountDetails[activeAccounts] == null)
{
System.out.println("Null entry");
}

else
{
accountDetails [activeAccounts] = new BankAccount(anAccountNumber, anAccountName, aBalance);
activeAccounts++;
anAccountNumber = Text.readLine(accountsFileIn);
}

}

accountsFileIn.close();
sortAccountDetails();
 
Back
Top Bottom