Array on jlabel/imageicon don't work

Hi!

I'm creating some kind of gamebuilder :) Just to learn. I wonder how to use arrays with jlabel/imageicon.

Here is my code:

JLabel[] jLabel1;

jLabel1 =new JLabel[10];

// When i try this the program stops

jLabel1[0].setIcon(new ImageIcon("lib\\image\\chest.PNG"));

When i try to start it i get an NullPointerException. Should i work with Buffered Images instead?

Thanks in advance!

[563 byte] By [hannesruns@hotmail.coma] at [2007-10-3 2:58:24]
# 1
Creating the array doesn't create the objects and assign references, you have to do that yourself.
kablaira at 2007-7-14 20:47:52 > top of Java-index,Java Essentials,New To Java...
# 2

Thanks!

Should i do like,

private JLabel[] jLabel1;

jLabel1 = new JLabel[10];

jLabel1[0] = new JLabel();

jLabel1[0].setIcon(new ImageIcon("lib\\image\\chest.PNG"));

addComponent(contentPane, jLabel1[0], 10,10,32,29);

hannesruns@hotmail.coma at 2007-7-14 20:47:52 > top of Java-index,Java Essentials,New To Java...
# 3
Bascially yes, but you might want to use a loop.
CeciNEstPasUnProgrammeura at 2007-7-14 20:47:52 > top of Java-index,Java Essentials,New To Java...
# 4
Thanks!I've fixed it now!
hannesruns@hotmail.coma at 2007-7-14 20:47:52 > top of Java-index,Java Essentials,New To Java...