ImgSet[0] = new ImageIcon("bandeira-portugal.png",
"Portugal");
ImgSet[1] = new ImageIcon("south_korea-32.png",
"South_Korea");
ImgSet[2] = new ImageIcon("China-icon.png",
"China");
ImgSet[3] = new ImageIcon("Japan.png",
"Japan");
This is my code for the image icons. I am getting the error message "java.lang.NullPointerException"! Can you please tell me how to fix it? My picture files are in the program folder!
Yes I did set the variable ImgSet if that's got anything to do with it.
private Icon[] ImgSet;
Initialize your array first. Thats all:)
Remember that you cannot change arrays length, after you initialize it, so select a good size, in this example it is 4. If your collection is dynamic (you will add more elements, depending on runtime), change it to list, or set. Remember that arrays are fast, but their size is not editable.