线程“ AWT-EventQueue-0”中的异常java.lang.ArrayIndexOutOfBoundsException:23

时间:2019-09-05 12:35:02

标签: java

我有此错误,我不知道出了什么问题

private void jTotalActionPerformed(java.awt.event.ActionEvent evt) {                                       
    // TODO add your handling code here:
    itemcost[0] = Double.parseDouble(jTxtGTX750.getText()) * 2500;
    itemcost[1] = Double.parseDouble(jTxtGTX750TI.getText()) * 2700;
    itemcost[2] = Double.parseDouble(jTxtGTX760.getText()) * 2800;
    itemcost[3] = Double.parseDouble(jTxtGTX770.getText()) * 3000;
    itemcost[4] = Double.parseDouble(jTxtGTX780.getText()) * 3300;
    itemcost[5] = Double.parseDouble(jTxtGTX780TI.getText()) * 3500;
    itemcost[6] = Double.parseDouble(jTxtGTX950.getText()) * 2700;
    itemcost[7] = Double.parseDouble(jTxtGTX960.getText()) * 3500;
    itemcost[8] = Double.parseDouble(jTxtGTX970.getText()) * 3800;
    itemcost[9] = Double.parseDouble(jTxtGTX980.getText()) * 5000;
    itemcost[10] = Double.parseDouble(jTxtGTX980TI.getText()) * 6000;
    itemcost[11] = Double.parseDouble(jTxtGTX1050.getText()) * 4500;
    itemcost[12] = Double.parseDouble(jTxtGTX1050TI.getText()) * 5500;
    itemcost[13] = Double.parseDouble(jTxtGTX10603GB.getText()) * 7500;
    itemcost[14] = Double.parseDouble(jTxtGTX10606GB.getText()) * 9000;
    itemcost[15] = Double.parseDouble(jTxtGTX1070.getText()) * 12000;
    itemcost[16] = Double.parseDouble(jTxtGTX1070TI.getText()) * 15000;
    itemcost[17] = Double.parseDouble(jTxtGTX1080.getText()) * 21000;
    itemcost[18] = Double.parseDouble(jTxtGTX1080TI.getText()) * 28000;
    itemcost[19] = Double.parseDouble(jTxtGTXTITANV.getText()) * 40000;

    itemcost[20] = itemcost[0] + itemcost[1] + itemcost[2] + itemcost[3] + itemcost[4] + itemcost[5] + itemcost[6];
    itemcost[21] = itemcost[7] + itemcost[8] + itemcost[9] + itemcost[10] + itemcost[11] + itemcost[12] + itemcost[13];
    itemcost[22] = itemcost[14] + itemcost[15] + itemcost[16] +itemcost[17] + itemcost[18] + itemcost[19];
    itemcost[23] = itemcost[20] + itemcost[21] + itemcost[22];

    iTax = String.format("Php %.2f", itemcost [23] / 100);
    iSubTotal = String.format("Php %.2f", itemcost [23]);
    iTotal = String.format("Php %.2f", itemcost [23] * (itemcost[23] / 100));

    jTxtTax.setText (iTax);
    jTxtSubTotal.setText (iSubTotal);
    jTxtTotal.setText (iTotal);

这些是我得到的错误 线程“ AWT-EventQueue-0”中的异常java.lang.ArrayIndexOutOfBoundsException:23     在PointOfSaleSystem.PointOfSaleSystem.jTotalActionPerformed(PointOfSaleSystem.java:1395)     在PointOfSaleSystem.PointOfSaleSystem.access处$ 8400(PointOfSaleSystem.java:16)     在PointOfSaleSystem.PointOfSaleSystem $ 85.actionPerformed(PointOfSaleSystem.java:1064)     在javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)     在javax.swing.AbstractButton $ Handler.actionPerformed(AbstractButton.java:2348)     在javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)     在javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)     在javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)     在java.awt.Component.processMouseEvent(Component.java:6539)     在javax.swing.JComponent.processMouseEvent(JComponent.java:3324)     在java.awt.Component.processEvent(Component.java:6304)     在java.awt.Container.processEvent(Container.java:2239)     在java.awt.Component.dispatchEventImpl(Component.java:4889)     在java.awt.Container.dispatchEventImpl(Container.java:2297)     在java.awt.Component.dispatchEvent(Component.java:4711)     在java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904)     在java.awt.LightweightDispatcher.processMouseEvent(Container.java:4535)     在java.awt.LightweightDispatcher.dispatchEvent(Container.java:4476)     在java.awt.Container.dispatchEventImpl(Container.java:2283)     在java.awt.Window.dispatchEventImpl(Window.java:2746)     在java.awt.Component.dispatchEvent(Component.java:4711)     在java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760)     在java.awt.EventQueue.access $ 500(EventQueue.java:97)     在java.awt.EventQueue $ 3.run(EventQueue.java:709)     在java.awt.EventQueue $ 3.run(EventQueue.java:703)     在java.security.AccessController.doPrivileged(本机方法)     在java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)     在java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84)     在java.awt.EventQueue $ 4.run(EventQueue.java:733)     在java.awt.EventQueue $ 4.run(EventQueue.java:731)     在java.security.AccessController.doPrivileged(本机方法)     在java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)     在java.awt.EventQueue.dispatchEvent(EventQueue.java:730)     在java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)     在java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)     在java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)     在java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)     在java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)     在java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

1 个答案:

答案 0 :(得分:0)

您应该将itemcost数组的大小增加1。

Double itemcost[] = new itemcost[24];