Solved

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

Posted on 2013-02-01
7
765 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 

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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

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 …
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

690 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