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]
应该用传递的参数t替换temp的最后一个元素,它是空的,而是错误。
只要临时尺码大于1,这个例外不应该发生吗?它所要做的就是修改最后一个元素。
答案 0 :(得分:3)
-1
是无效的数组索引。如果您尝试设置最后一个元素,则应为
temp[temp.length-1] = t;