Hi all,
I try to expand my array by doing this.
for(int x=0; x < account.length;x++)
{ //System.out.println("in For loop,AccountNumber:"+ account[x].getAccountNumber());
int anumber = account[x].getAccountNumber();
if(anumber == Anums)
{ Match = "true";
aindex = x;
break;}
}
if(Match == "true")
{
int testnum = 500;
int testbalance = account[aindex].getBalance();
int finalbalance = testbalance + testnum;
account[aindex].setBalance(finalbalance);
//System.out.println("Account NO: " + account[aindex].getAccountNumber() + "-- Balance:" + account[aindex].getBalance());
}
else
{
int Len = account.length;
int newLen = Len + 1;
Account[] newArray = new Account[newLen];
System.arraycopy(account, 0, newArray, 0,Len);
account = newArray;
//account = Arraysize.arrayExpand(account);
int iindex = account.length;
int ibal = 0;
System.out.println("AccountLength:"+ iindex);
account[iindex] = new Account(Anums, ibal);
// String aM = "false";
// vMutex.addElement(aM);
}
I encounter this error.
java.lang.ArrayIndexOutOfBoundsExpection: 7 at ATM.run(ATM.java: 157)
The line 157 is: account[iindex] = new Account(Anums, ibal);
Do you know where I do wrong?
Thanks....
Mike