Got DBTableHeaderFill Error: ArrayIndexOutOfBoundsException = 0
and can't figure it out, why does it appears...
col is 11 because table has 12 headers, as we know the counting starts form 0
i know it looks primitive, but i'm just debugging the problem ... JOptionPane is for seeing what works what not, and i can't figure whats the problem whit arrays...
    Object rows[][] = new Object[row][col];
    Object columns [] = new Object[col];
    row = 1;
    col = 11;
    JTable table = new JTable(rows, columns);
    scrollPane.setViewportView(table);
    /*
     *  DataBase Headers
     */
    try{
        conn = DBConnection.DBConnector();
        JOptionPane.showMessageDialog(null, "Connection");
        Statement st = conn.createStatement();
        JOptionPane.showMessageDialog(null, "Statement");
        rs = st.executeQuery("SELECT * FROM Query1");
        JOptionPane.showMessageDialog(null, "Query1 load");
        ResultSetMetaData rsmd = rs.getMetaData();
        JOptionPane.showMessageDialog(null, rsmd);
        int columnCount = rsmd.getColumnCount();
        JOptionPane.showMessageDialog(null, columnCount);
        JOptionPane.showMessageDialog(null, "test " + col);
        // The column count starts from 0
        for (int i = 1; i < columnCount + 1; i++ ) {
            columns[i-1] = rsmd.getColumnName(i);
            JOptionPane.showMessageDialog(null, "result: " + o);
            JOptionPane.showMessageDialog(null, "Header" + columns[i-1]);
          // Writes headers
        }
    }catch(Exception e){
        JOptionPane.showMessageDialog(null, "DBTableHeaderFill Error: " + e);
    }
When i assign col and row values before arrays i get this errors:
java.lang.NullPointerException at javax.swing.JTable$1.getColumnName(Unknown Source) at javax.swing.JTable.addColumn(Unknown Source) at javax.swing.JTable.createDefaultColumnsFromModel(Unknown Source) at javax.swing.JTable.tableChanged(Unknown Source) at javax.swing.JTable.setModel(Unknown Source) at javax.swing.JTable.(Unknown Source) at javax.swing.JTable.(Unknown Source) at javax.swing.JTable.(Unknown Source) at Main.initialize(Main.java:199) at Main.(Main.java:65) at Main$1.run(Main.java:34) at java.awt.event.InvocationEvent.dispatch(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$300(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)
So i found my problem...
JTable table = new JTable(rows, columns);
scrollPane.setViewportView(table);
this needs to be at the end of the arrays....
 
     
    