在将文本字段中的值插入名为java.lang.IndexOutOfBoundsException Index: 0, Size: 0
的表中后,尝试保存时出现table_po
错误。请帮助
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);
}
}
答案 0 :(得分:1)
很可能这部分代码必须为您提供java.lang.IndexOutOfBoundsException Index: 0, Size: 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();
在控制台中获取堆栈跟踪。