由於某種原因,當我嘗試的元素添加到ListModel
,我不斷收到此錯誤:錯誤,而試圖將元素添加到一個ListModel的
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 1 >= 1
這是代碼,它發生在塊:
if (shoppingCart.getModel().getSize() > 0)
{
for (int i = 0; i <= shoppingCart.getModel().getSize();i++)
{
Object a = shoppingCart.getModel().getElementAt(i);
System.out.println(a.toString()); // this is to test if it gets the right value
// it does.
booksToAdd.addElement(a.toString()); //but here it cannot add it
}
}
我不明白什麼是錯的。我試圖做研究,並且提出了一些有關數組越界的問題,但是我不知道數組與這個有什麼關係。
檢查表'booksToAdd' –