Solved

System throwing Exception occurred during event dispatching: java.lang.ArrayIndexOutOfBoundsException: 5 while creating JTable in NetBeans

Posted on 2013-02-01
7
759 Views
Last Modified: 2013-02-01
Dear Experts,
I am trying to create a JDialow containing JTable. I am reading data from MS-Access database and creating JTables.  I am working in NetBeans. My observation is that the system is having limitation of creating at most Five columns. When I add sixth column and populate values from Database, it throws the exception
Exception occurred during event dispatching: java.lang.ArrayIndexOutOfBoundsException: 5
I have tried from all angles but unable to fix the problem. Please help.

Regards
0
Comment
Question by:MILIND_JOG
  • 4
  • 3
7 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 38843163
Full stack trace please
0
 

Author Comment

by:MILIND_JOG
ID: 38843168
Dear CEHJ,

Thanks for quick response. The stack trace is as under.

Exception occurred during event dispatching:
java.lang.ArrayIndexOutOfBoundsException: 5
      at updateDiarylines$1.getColumnClass(updateDiarylines.java:82)
      at javax.swing.JTable.getColumnClass(JTable.java:2667)
      at javax.swing.JTable.getCellRenderer(JTable.java:5671)
      at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:2071)
      at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:1974)
      at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:1770)
      at javax.swing.plaf.ComponentUI.update(ComponentUI.java:143)
      at javax.swing.JComponent.paintComponent(JComponent.java:760)
      at javax.swing.JComponent.paint(JComponent.java:1037)
      at javax.swing.JComponent.paintChildren(JComponent.java:870)
      at javax.swing.JComponent.paint(JComponent.java:1046)
      at javax.swing.JViewport.paint(JViewport.java:752)
      at javax.swing.JComponent.paintChildren(JComponent.java:870)
      at javax.swing.JComponent.paint(JComponent.java:1046)
      at javax.swing.JComponent.paintChildren(JComponent.java:870)
      at javax.swing.JComponent.paint(JComponent.java:1046)
      at javax.swing.JComponent.paintChildren(JComponent.java:870)
      at javax.swing.JComponent.paint(JComponent.java:1046)
      at javax.swing.JLayeredPane.paint(JLayeredPane.java:567)
      at javax.swing.JComponent.paintChildren(JComponent.java:870)
      at javax.swing.JComponent.paintToOffscreen(JComponent.java:5139)
      at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1491)
      at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1422)
      at javax.swing.RepaintManager.paint(RepaintManager.java:1225)
      at javax.swing.JComponent.paint(JComponent.java:1023)
      at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)
      at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
      at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)
      at java.awt.Container.paint(Container.java:1778)
      at java.awt.Window.paint(Window.java:3390)
      at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:797)
      at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:714)
      at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:694)
      at javax.swing.RepaintManager.access$700(RepaintManager.java:41)
      at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1636)
      at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
      at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:666)
      at java.awt.EventQueue.access$400(EventQueue.java:81)
      at java.awt.EventQueue$2.run(EventQueue.java:627)
      at java.awt.EventQueue$2.run(EventQueue.java:625)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:636)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:178)
      at java.awt.Dialog$1.run(Dialog.java:1047)
      at java.awt.Dialog$3.run(Dialog.java:1099)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.awt.Dialog.show(Dialog.java:1097)
      at java.awt.Component.show(Component.java:1591)
      at java.awt.Component.setVisible(Component.java:1543)
      at java.awt.Window.setVisible(Window.java:843)
      at java.awt.Dialog.setVisible(Dialog.java:987)
      at updateDiarylines$2.run(updateDiarylines.java:248)
      at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
      at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:666)
      at java.awt.EventQueue.access$400(EventQueue.java:81)
      at java.awt.EventQueue$2.run(EventQueue.java:627)
      at java.awt.EventQueue$2.run(EventQueue.java:625)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:636)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

Regards
0
 

Author Comment

by:MILIND_JOG
ID: 38843212
Dear CEHJ,

My observation is that when I add row eliments into vector, it gives the problem. The piece of code is as follows.

jTable1 = new javax.swing.JTable();
Vector columnNames = new Vector();
//columnNames.setSize(6);
Vector data = new Vector();
columnNames.addElement("Room_No");
columnNames.addElement("Name");
columnNames.addElement("S_Code");
columnNames.addElement("S_Name");
columnNames.addElement("Amount");
columnNames.addElement("Remark");
columnNames.setSize(6);
      DBInterface dbi = DBInterface.getInstance();
        try {
            Connection c = dbi.getConnection();
            ResultSet rsColumns = null;
            PreparedStatement Stmt = c.prepareStatement("SELECT a.code as code,b.name as name,a.s_code as scode,c.s_name as sname,a.rd_amt ,a.remark as remark FROM diary a, guestPresentView b , Service c where a.code = b.code and a.s_code = c.s_code");            
            ResultSet myResult = Stmt.executeQuery();
                while (myResult.next())
                {
                    Vector row1 = new Vector();
                    row1.addElement(myResult.getString("code"));
                    row1.addElement(myResult.getString("name"));
                    row1.addElement(myResult.getString("scode"));
                    row1.addElement(myResult.getString("sname"));
                    row1.addElement(myResult.getDouble("rd_amt"));
                    row1.addElement(myResult.getString("remark"));
                   data.addElement( row1 );
                }
            }
        catch (Exception e)
            {
                System.out.println(e);
            }
jTable1.setModel(new javax.swing.table.DefaultTableModel(
data,columnNames)
 {
    Class[] types = new Class [] {
        java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
    };

    public Class getColumnClass(int columnIndex) {
        return types [columnIndex];
    }

    public boolean isCellEditable(int row, int col)
    {
            //System.out.println("I am here");
            return true;
    }

});


The underlined bold statement is giving the problem.

Regards
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:MILIND_JOG
ID: 38843298
Dear CEHJ,

Please advice your sugestion.

Regards
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 38843342
You missed Double.class out of 'types'
0
 

Author Closing Comment

by:MILIND_JOG
ID: 38843367
Dear CEHJ,

Excelent. I realy extend my thanks. Your sugestion resolved the issue at once.

Once again thanks.

Regards
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 38843521
:)
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

697 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question