java - NullPointerException, Trying to add JPanel Array to Container -


can't figure out why getting exception, console returns message:

public static void main(string [] args){ jframe b = new jframe("lotus"); container pieces = new container(); jlabel[] labelsp1 = new jlabel[10]; jlabel[] labelsp2 = new jlabel[10];  for(int = 0 ; < labelsp1.length ; i++){     labelsp1[i] = new jlabel(b1);      for(int j = 0 ; j < labelsp2.length ; j++){         labelsp2[j] = new jlabel(b2);      }     (jlabel label : labelsp1) {         pieces.add(label);     }      container c = b.getcontentpane();     c.setlayout(new gridlayout(13,3));      c.add(pieces); } 

your 3rd inner loop iterating throw null array

 (jlabel label : labelsp1) {         pieces.add(label);     } 

//

for(int = 0 ; < labelsp1.length ; i++) {     labelsp1[i] = new jlabel(b1);      for(int j = 0 ; j < labelsp2.length ; j++)     {         labelsp2[j] = new jlabel(b2);      }     (jlabel label : labelsp1)   // null labelsp1[0] initialized     {         pieces.add(label);             }      container c = b.getcontentpane();     c.setlayout(new gridlayout(13,3));      c.add(pieces); } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -