索引越界异常:无法弄清楚发生了什么事?作业 [英] Index out of bounds exception: cant figure out what is happening? School Assignment
问题描述
这是使用计算器的,我需要问一个问题我的第一次,所以希望我能得到一些帮助。这是我工作的一个作业,虽然我已经在把它和我将很快彻底改变code pretty,我想弄清楚什么是错在先。这基本上是一个购买历史节目,其中过去的购买存储,并可以作为一个'下一个'和'回'按钮收据进行访问。没有文件访问,并且是随机生成的所有数据。随机数据生成不是任务的要求,但我想这样做的一个学习的经验。
This is my first time using stackoverflow for a question that I need to ask, so hopefully I can get some help. This is a school assignment that I am working on, and although I have already turned it in and am going to change the code pretty drastically soon, I would like to figure out what is wrong first. This is basically a purchase history program, where the past purchases are stored and can be accessed as receipts with a 'next' and 'back' button. There is no file access, and all the data is generated randomly. The random data generation wasn't a requirement of the assignment, but I wanted to do it that way as a learning experience.
在的问题,这是怎么回事这个错误?
On to the question, what is going on with this error?
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)
有很多code,可能是太多,张贴在这里,所以这里是到源链接:
http://www.mediafire.com/?3ogc334vwh6t7k6
There is a lot of code, probably too much to post here, so here is a link to the source: http://www.mediafire.com/?3ogc334vwh6t7k6
下面是code的点在哪里发生错误:
Here are the spots of code where the error occurs:
在farmmark.Storage.getItems(Storage.java:36)
at farmmark.Storage.getItems(Storage.java:36)
public static String[] getItems(int select)
{
return itemList.get(select);
}
在farmmark.Gui.buttonActionNext(Gui.java:415)
at farmmark.Gui.buttonActionNext(Gui.java:415)
String items[] = Storage.getItems(counter);
在farmmark.Gui $ ButtonHandler.actionPerformed(Gui.java:631)
at 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。在先进的感谢!
Any help would be great, keep in mind I have only been programming in java for 8 weeks :P. Thanks in advanced!
推荐答案
下面是在哪里看:
at farmmark.Storage.getItems(Storage.java:36)
下面的方法:
public static String[] getItems(int select)
{
return itemList.get(select);
}
为的值选择
是不是小于零或大于(itemList.length-1)
。
运行,在该行设置断点,看看是怎么回事。
Run in a debugger, set a breakpoint at that line, and see what's up.
我没有看到任何ITEMLIST或选择设置。看看这些方法为好。
I don't see where either itemList or select is set. Take a look at those methods as well.
只是好奇 - 为什么是静态的方法
Just curious - why is that method static?
这篇关于索引越界异常:无法弄清楚发生了什么事?作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!