swing - how to resolve ,"AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 -
public class queryresult extends javax.swing.jframe { int pos=0; string companyvalue; string colorvalue; string reviewvalue; public queryresult() { companyvalue=newjframe1.query_company; colorvalue=newjframe1.query_color; reviewvalue=newjframe1.query_review; system.out.println("vaule coming "+companyvalue); system.out.println("value "+colorvalue); system.out.println("value "+reviewvalue); initcomponents(); showitem(pos); } public void getconncetion() { connection conshow=null; string userquery=""; resultset showdata=null; try { class.forname("oracle.jdbc.driver.oracledriver"); conshow=drivermanager.getconnection("jdbc:oracle:thin:@localhost:1521:xe","system","root"); }catch(classnotfoundexception ex) { } catch (sqlexception ex) { logger.getlogger(queryresult.class.getname()).log(level.severe, null, ex); } } /** * * @return */ public list<itemshow> getitemslist() { connection conshow=null; string userquery=""; resultset showdata=null; try { class.forname("oracle.jdbc.driver.oracledriver"); conshow=drivermanager.getconnection("jdbc:oracle:thin:@localhost:1521:xe","system","root"); }catch(classnotfoundexception ex) { ex.printstacktrace(); } catch (sqlexception ex) { logger.getlogger(queryresult.class.getname()).log(level.severe, null, ex); } preparedstatement stmt=null; list<itemshow> list=new arraylist<itemshow>(); itemshow item; userquery="select * recorddata company_nm='"+companyvalue+"'and review= '"+reviewvalue+"'and color_nm= '"+colorvalue+"'"; try { stmt=conshow.preparestatement(userquery); showdata=stmt.executequery(); while(showdata.next()) { item =new itemshow(showdata.getint(1),showdata.getstring(2),showdata.getstring(3), showdata.getstring(4),showdata.getstring(5),showdata.getstring(6),showdata.getstring(7),showdata.getbytes(8)); list.add(item); } return list; } catch (sqlexception ex) { logger.getlogger(queryresult.class.getname()).log(level.severe, null, ex); return null; } } public void showitem(int index) { jtextfield_id.settext(integer.tostring(getitemslist().get(index).getid())); jtextfield_company.settext(getitemslist().get(index).getcompany()); jtextfield_model.settext(getitemslist().get(index).getmodel()); jtextfield_style.settext(getitemslist().get(index).getstyle()); jtextfield_color.settext(getitemslist().get(index).getcolor()); jtextfield_quality.settext(getitemslist().get(index).getquality()); jtextfield_review.settext(getitemslist().get(index).getreview()); imageicon icon= new imageicon(getitemslist().get(index).getimage()); image image=icon.getimage().getscaledinstance(jlabel2.getwidth(),jlabel2.getheight(),image.scale_smooth); jlabel2.seticon(new imageicon(image)); }
the values of companyvalue,colorvalue,reviewvalue taken frame choicebox. when user clicks on submit button on frame1 second frame should come in picture , shows frame2 required data (which read database).
above code throws exception in thread "awt-eventqueue-0" java.lang.indexoutofboundsexception. don't know why? gives error
exception in thread "awt-eventqueue-0" java.lang.indexoutofboundsexception: index: 0, size: 0
at java.util.arraylist.rangecheck(arraylist.java:635) @ java.util.arraylist.get(arraylist.java:411) @ javaapplication1.queryresult.showitem(queryresult.java:156) @ javaapplication1.queryresult.<init>(queryresult.java:50) @ javaapplication1.queryresult$12.run(queryresult.java:490) @ java.awt.event.invocationevent.dispatch(invocationevent.java:251) @ java.awt.eventqueue.dispatcheventimpl(eventqueue.java:733) @ java.awt.eventqueue.access$200(eventqueue.java:103) @ java.awt.eventqueue$3.run(eventqueue.java:694) @ java.awt.eventqueue$3.run(eventqueue.java:692) @ java.security.accesscontroller.doprivileged(native method) @ java.security.protectiondomain$1.dointersectionprivilege(protectiondomain.java:76) @ java.awt.eventqueue.dispatchevent(eventqueue.java:703) @ java.awt.eventdispatchthread.pumponeeventforfilters(eventdispatchthread.java:242) @ java.awt.eventdispatchthread.pumpeventsforfilter(eventdispatchthread.java:161) @ java.awt.eventdispatchthread.pumpeventsforhierarchy(eventdispatchthread.java:150) @ java.awt.eventdispatchthread.pumpevents(eventdispatchthread.java:146) @ java.awt.eventdispatchthread.pumpevents(eventdispatchthread.java:138) @ java.awt.eventdispatchthread.run(eventdispatchthread.java:91)
might query returns 0 rows.
make sure getitemslist()
not empty
Comments
Post a Comment