This is driving me nuts!
I used both concatenation and format and while the strings produced match the correct paths, the loop throws exceptions from the get go.
what’s going on?
ImageIcon thisWorks= new ImageIcon(testview.class.getResource("/led_images/"+1+"_off.png"));
for(int i = 1; i <= 10; i++)
{
String on = String.format("/led_images/%d_on.png",i);
String off = String.format("/led_images/%d_off.png",i);
ledIcons.put( i+"_off", new ImageIcon(testview.class.getResource(off)));
ledIcons.put( i+"_on", new ImageIcon(testview.class.getResource(on)));
}
Edit:
am I using Map incorrectly?
It’s a Map<String,ImageIcon> one.
Edit2:
Yeah I guess I’m using the map incorrectly.
I have it declared like this:
public Map< String, ImageIcon> ledIcons;
It’s a null value inside the loop.
So I guess it’s not like c++ then?
Edit3:
Yeah, nevermind this question, I didn’t initialize the field properly, my apologies.
Initialize the field: