由于某种原因,当我尝试的元素添加到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' –