如何解决,“AWT-EventQueue-0”java.lang.IndexOutOfBoundsException:索引:0,大小:0

时间:2016-06-11 06:11:34

标签: java swing jdbc awt

    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 is coming "+companyvalue);
            System.out.println("Value is "+colorvalue);
            System.out.println("Value is "+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 * from RECORDDATA where 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));
        }

companyvalue,colorvalue,reviewvalue的值取自另一个带有choicebox的框架。当用户点击第1帧上的提交按钮时,第二帧应该进入图片并显示带有所需数据的frame2(从数据库中读取)。

上面的代码在线程“AWT-EventQueue-0”中抛出异常java.lang.IndexOutOfBoundsException。我不知道为什么?它给出了错误

  

线程中的异常“AWT-EventQueue-0”java.lang.IndexOutOfBoundsException:Index:0,Size:0

at java.util.ArrayList.rangeCheck(ArrayList.java:635)
at java.util.ArrayList.get(ArrayList.java:411)
at javaapplication1.queryresult.showitem(queryresult.java:156)
at javaapplication1.queryresult.<init>(queryresult.java:50)
at javaapplication1.queryresult$12.run(queryresult.java:490)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

1 个答案:

答案 0 :(得分:1)

可能是查询返回零行。

确保/home/vagrant/Code/homestead/vendor/autoload.php 不为空