Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java.lang.IndexOutOfBoundsException索引:0,大小:0_Java - Fatal编程技术网

java.lang.IndexOutOfBoundsException索引:0,大小:0

java.lang.IndexOutOfBoundsException索引:0,大小:0,java,Java,在将文本字段中的值插入名为table\u po的表中后,尝试保存时出现java.lang.IndexOutOfBoundsException索引:0,大小:0错误。好心协助 private void saveActionPerformed(java.awt.event.ActionEvent evt) { try{ if(cbo_payment.getSelectedItem().equals("Paymen

在将文本字段中的值插入名为
table\u po
的表中后,尝试保存时出现
java.lang.IndexOutOfBoundsException索引:0,大小:0
错误。好心协助

private void saveActionPerformed(java.awt.event.ActionEvent evt)
{                                     
  try{
     if(cbo_payment.getSelectedItem().equals("Payment Mode")){
         JOptionPane.showMessageDialog(null, "Select a valid payment mode before saving");
            return;
     }

     if(table_po.getModel().getValueAt(0, 0)==null){
            JOptionPane.showMessageDialog(null, "Select products before saving");
            return;
      }

    for(int i=0;i<saleListCounter;i++){
          String sql="insert into OT_PURCHASE_ORDER (part_no,ITEM_DESCRIPTION,QUANTITY,AMOUNT,PAYMENT_MODE,SUPPLIER_ID,PO_DATE,EXP_DATE) values(?,?,?,?,?,?,?,?,?)";
          pst=conn.prepareStatement(sql);             
          pst.setString(1, table_po.getModel().getValueAt(i, 0).toString());
          pst.setString(2, table_po.getModel().getValueAt(i, 1).toString());
          pst.setString(3, table_po.getModel().getValueAt(i, 2).toString());
          pst.setString(4, table_po.getModel().getValueAt(i, 3).toString());
          pst.setString(5, (String)cbo_payment.getSelectedItem());
          int index=((int)list.get(cbo_supplier.getSelectedIndex()));
          pst.setInt(6, index);
          //pst.setString(7, lblCash.getText());
          pst.setString(7, ((JTextField)txt_Expdate.getDateEditor().getUiComponent()).getText());
          pst.setString(8, ((JTextField)txt_date.getDateEditor().getUiComponent()).getText());

          pst.execute();
          pst.close();
           sql="select max (po_id) as POIDfrom fm_credit_sale";
           pst=conn.prepareStatement(sql);
          rs=pst.executeQuery();
          if(rs.next()){
              transactionCounter.add(rs.getInt("POID"));

          }
          transactioncounter++;
    }

     for(int i=0;i<saleListCounter;i++){             
         table_po.getModel().setValueAt(null, i, 0);
         table_po.getModel().setValueAt(null, i, 1);
         table_po.getModel().setValueAt(null, i, 2);
         table_po.getModel().setValueAt(null, i, 3);
         table_po.getModel().setValueAt(null, i, 4);
     }

     total=saleListCounter=0;
     lblCash.setText(null);

     JOptionPane.showMessageDialog(null, "SAVED SUCCESSFULLY");
   }catch(Exception e){
       JOptionPane.showMessageDialog(null, e);
   }    
}                                    
private void saveActionPerformed(java.awt.event.ActionEvent evt)
{                                     
试一试{
如果(cbo_payment.getSelectedItem().equals(“支付模式”)){
showMessageDialog(null,“保存前选择有效的支付模式”);
返回;
}
如果(表_po.getModel().getValueAt(0,0)==null){
showMessageDialog(null,“保存前选择产品”);
返回;
}

对于(int i=0;i,很可能这部分代码必须为您提供一个
java.lang.IndexOutOfBoundsException索引:0,大小:0
:-

 if(table_po.getModel().getValueAt(0, 0)==null){
        JOptionPane.showMessageDialog(null, "Select products before saving");
        return;
  }
使用此代码:-

try{
 if(table_po.getModel().getValueAt(0, 0)==null){
        JOptionPane.showMessageDialog(null, "Select products before saving");
        return;
  }
}catch(Exception e){ return; }

进一步说明:Java也提供了异常的堆栈跟踪。您可以获取异常发生的行号,并能够识别问题。使用
e.printStackTrace();
在控制台中获取堆栈跟踪。

这意味着您正试图访问索引
0
中不存在的内容(此集合为空)。在尝试访问之前,请先插入某些内容。