Solved

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

Posted on 2013-02-01
7
753 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
eclipse argument 14 61
Maven Project: Hibernate Dependencies Conflict 10 24
servlet example 17 32
Java: anonymous class 4 22
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

809 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