這是我第一次使用stackoverflow的問題,我需要問,所以希望我可以得到一些幫助。這是我正在開展的一項學校任務,雖然我已經開始着手開發,並且要儘快更改代碼,但我想先弄清楚什麼是錯誤的。這基本上是一個購買歷史記錄程序,其中過去的購買被存儲並且可以作爲具有「下一個」和「後退」按鈕的收據訪問。沒有文件訪問,並且所有數據都是隨機生成的。隨機數據生成不是這項任務的要求,但我想這樣做是一種學習體驗。索引越界異常:不知道發生了什麼?學校作業
在這個問題上,這個錯誤是怎麼回事?
Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 9, Size: 9
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at farmmark.Storage.getItems(Storage.java:36)
at farmmark.Gui.buttonActionNext(Gui.java:415)
at farmmark.Gui$ButtonHandler.actionPerformed(Gui.java:632)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6290)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6055)
at java.awt.Container.processEvent(Container.java:2039)
at java.awt.Component.dispatchEventImpl(Component.java:4653)
at java.awt.Container.dispatchEventImpl(Container.java:2097)
at java.awt.Component.dispatchEvent(Component.java:4481)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4575)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4236)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4166)
at java.awt.Container.dispatchEventImpl(Container.java:2083)
at java.awt.Window.dispatchEventImpl(Window.java:2482)
at java.awt.Component.dispatchEvent(Component.java:4481)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:648)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:607)
at java.awt.EventQueue$1.run(EventQueue.java:605)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$2.run(EventQueue.java:621)
at java.awt.EventQueue$2.run(EventQueue.java:619)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:618)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
BUILD SUCCESSFUL (total time: 6 seconds)
有很多的代碼,可能是太多,張貼在這裏,所以這裏是到源鏈接: http://www.mediafire.com/?3ogc334vwh6t7k6
這裏是代碼點在錯誤發生時:
在farmmark.Storage.getItems(Storage.java:36)
public static String[] getItems(int select)
{
return itemList.get(select);
}
在farmmark.Gui.buttonActionNext(Gui.java:415)
String items[] = Storage.getItems(counter);
在farmmark.Gui $ ButtonHandler.actionPerformed(Gui.java:631)
else if(sel.equals("Next"))
{
jtxtItems.setText(null);
jtxtPrices.setText(null);
jtxtSkus.setText(null);
jtxtCase.setText(null);
jtxtVend.setText(null);
panel.removeAll();
buttonActionNext();
{
任何幫助將是巨大的,記住我只在Java編程8周:P 。先謝謝了!
'itemList.get(select)'選擇一個超出列表邊界的索引。 'select'的價值是什麼? –
您是否嘗試過使用調試程序執行程序? – Zavior
您提供的鏈接帶有「病毒警報」消息(虛假)彈出窗口... – Attila