title: Array required but object found - java
body: <p>I'm new to java. I'm following a tutorial to retrieve images and other data from db to a jTable. Data will retrieve to an ArrayList first, and I get this error saying array required but object found. I have added all my code. The error is in the <code>TheModel.java</code> file. Any help would be appreciated.</p>
  
  <p><strong>Course.java</strong></p>
  
  <pre><code>package my.welcomescreen;
  
  
  public class Course {
      private int id;
      private String name;
      private byte[] imag;
      private String desc;
  
  public Course(){}
  
  public Course(int Id, String Name, byte[] image, String description){
      this.id = Id;
      this.name = Name;
      this.imag = image;
      this.desc = description;
  }
  
  public int getID(){
      return id;
  }
  
  public void setID(int ID){
      this.id = ID;
  }
  
  public String getName(){
      return name;
  }
  
  public void setName(String Name){
      this.name = Name;
  }
  
  public byte[] getImage(){
      return imag;
  }
  
  public String getDesc(){
      return desc;
  }
  
  public void setDesc(String Description){
      this.desc = Description;
  }
  }
  </code></pre>
  
  <p><strong>MainQuery.java</strong></p>
  
  <pre><code>package my.welcomescreen;
  
  import java.sql.Connection;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import java.sql.Statement;
  import java.util.ArrayList;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  
  public class MainQuery {
  
      public ArrayList&lt;Course&gt; BindTable(){
      ArrayList&lt;Course&gt; list = new ArrayList&lt;Course&gt;();
      db databaseCon = new db();
      Connection dbconnect = db.dbconnect();
      Connection con = databaseCon.dbconnect();
      Statement st;
      ResultSet rs;
  
      try{
          st = con.createStatement();
          String sql = "select id,name,img,description from courses";
          rs = st.executeQuery(sql);
  
          Course c;
          while(rs.next()){
              c = new Course(
                              rs.getInt("id"),
                              rs.getString("name"),
                              rs.getBytes("img"),
                              rs.getString("description")
                             );
  
          }
  
      } catch (SQLException ex) {
          Logger.getLogger(Admin_Panel.class.getName()).log(Level.SEVERE, null, ex);
      }
  
      return list;
  
     }
  
  
  }
  </code></pre>
  
  <p><strong>TheModel.java</strong></p>
  
  <pre><code>package my.welcomescreen;
  
  import javax.swing.Icon;
  import javax.swing.table.AbstractTableModel;
  
  
  public class TheModel extends AbstractTableModel {
  
      private String[] columns;
      private Object[] rows;
  
      public TheModel(){}
  
      public TheModel(Object[][] data, String[] columnName){
          this.rows = data;
          this.columns = columnName;
      }
  
      public Class getColumnClass(int Column){
          if(Column == 2){
              return Icon.class;
          } else {
              return getValueAt(0,Column).getClass();
          }
      }
  
  
      public int getRowCount() {
          return this.rows.length;
      }
  
  
      public int getColumnCount() {
          return this.columns.length;
      }
  
  
  public Object getValueAt(int rowIndex, int columnIndex) {
       return this.rows[rowIndex][columnIndex]; //this is the error line : array required but object found
  }
  
  public String getColumnName(int col){
      return this.columns[col];
  }
  
  }
  </code></pre>
  
  <p><strong>Main Method</strong></p>
  
  <pre><code>public void displayJTable(){
      MainQuery mq = new MainQuery();
      ArrayList&lt;Course&gt; list = mq.BindTable();
      String[] columnName = {"Id","Course Name","Image","Description"};
      Object[][] rows = new Object[list.size()][3];
      for(int i = 0; i &lt; list.size(); i++){
          rows[i][0] = list.get(i).getID();
          rows[i][1] = list.get(i).getName();
  
          if(list.get(i).getImage() != null){
  
           ImageIcon image = new ImageIcon(new ImageIcon(list.get(i).getImage()).getImage()
           .getScaledInstance(150, 120, Image.SCALE_SMOOTH) );   
  
          rows[i][2] = image;
          }
  
          rows[i][3] = list.get(i).getDesc();
      }
  
      TheModel model = new TheModel(rows, columnName);
      jTable1.setModel(model);
      jTable1.setRowHeight(120);
      jTable1.getColumnModel().getColumn(3).setPreferredWidth(150);
  
  
  }
  </code></pre>