-1
public void addTransaction(Transaction t){
    mSize++;
    Transaction[] temp = new Transaction[mSize];
    System.arraycopy(mTransactions, 0, temp, 0, mSize - 1);
    temp[-1] = t // ERROR HERE
    mTransactions = temp;
}

temp[-1] should replace the last element of temp, which is empty, with the passed argument t, but instead errors.

As long as temp's size is greater than 1, this exception shouldn't happen right? All it's trying to do is modify the last element.

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
MaxG
  • 65
  • 3

1 Answers1

3

-1 is an invalid array index. If you're trying to set the last element, it should be

temp[temp.length-1] = t;
shmosel
  • 49,289
  • 6
  • 73
  • 138