Solved

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

Posted on 2013-02-01
7
757 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xampp tool 12 56
Oracle SQL syntax check  without executing 6 74
login jsp example 24 62
ejb entity bean example 2 7
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 …
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 learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
The viewer will learn how to implement Singleton Design Pattern in Java.

789 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