I want to create JLabel with icon in for loop.
Here is my code;
final JLabel[] box = new JLabel[27];
for(int i = 0; i < 25; i++){
int j = 1;
String r = "case" + j + ".png";
box[i] = new JLabel(new ImageIcon(getClass().getResource(r)));
j++;
}
names of icons are like case1.png, case2.png;....
But there is a null point exception.
Exception in thread "main" java.lang.NullPointerException at
java.awt.Container.addImpl(Unknown Source) at java.awt.Container.add(Unknown Source)
at Game.<init>(Game.java:185) at Game.main(Game.java:243) here are the exceptions
Is it just because I did not create names of icons truely? Thanks in advance.
box?