Solved

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

Posted on 2013-02-01
7
744 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
scoreUp challenge 14 48
mapShare challenge 13 69
Saving Tweets with emojis using Twitter4J in a Mysql table 2 53
groovy example issue 10 70
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
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.

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now