java.lang.IndexOutOfBoundsException Index: 0, Size: 0 -



java.lang.IndexOutOfBoundsException Index: 0, Size: 0 -

i getting java.lang.indexoutofboundsexception index: 0, size: 0 error when trying save after inserting values textfields table named table_po. kindly assist

private void saveactionperformed(java.awt.event.actionevent evt) { try{ if(cbo_payment.getselecteditem().equals("payment mode")){ joptionpane.showmessagedialog(null, "select 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 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) 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); } }

most part of code must giving java.lang.indexoutofboundsexception index: 0, size: 0 :-

if(table_po.getmodel().getvalueat(0, 0)==null){ joptionpane.showmessagedialog(null, "select products before saving"); return; }

use code :-

try{ if(table_po.getmodel().getvalueat(0, 0)==null){ joptionpane.showmessagedialog(null, "select products before saving"); return; } }catch(exception e){ return; }

further notes : java gives stack trace of exception too. can line number exception occurring , able identify problem. utilize e.printstacktrace(); stack trace in console.

java

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -