When you debug, look at the value of panel[counter]....an array of JPanel's is created, but the members of that array must each be instantiated.