in this program i wanted to load images in array of image in netbeans. the program works if i read a single picture. however when i used a loop to load the pictures, i get error exactly at "labelx.seticon(imageicon)". as you see i tested if the icons are null and got the message they are not null. any help will be apprciated. the error i got an error in main thread nullpointer exceptions. thanks
public class Image_array2 {
/**
* @param args the command line arguments
*/
public Image_array2()
{
photo();
}
public static void main(String[] args) {
new Image_array2();
int g=5;
Image [] arrayimages = new Image[49];
System.out.println("gamal" + g);
// TODO code application logic here
}
public void photo()
{
//try{
ImageIcon myicon;
ImageIcon[] icons = new ImageIcon[3];
JFrame frame = new JFrame();
frame.setSize(900,900);
JLabel[] labelx = new JLabel[3];
JLabel mylabel = null;
Image image;
for(int i = 0 ; i<3;i++)
{
// image= new ImageIcon(this.getClass().getResource("src/image_array2/mycards/image"+i+".jpg")).getImage();
//// Image img = new ImageIcon(this.getClass().getResource("src/image_array2/mycards/image22.jpg")).getImage();
//if(img == null)
// System.out.println(" it is nothting");
// else
//System.out.println("it is okay");
icons[i] = new ImageIcon("src/image_array2/mycards/image"+i+".jpg");
myicon = icons[i];
if(myicon == null)
System.out.println(" it is nothting");
else
System.out.println("it is okay");
labelx[i].setIcon(icons[i]);
//label[0].setIcon(icons[i]);
// mylabel.setIcon(myicon);
// frame.add(label[i]); }
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
// } catch(IOException e) {}
}
}
}