Hi,
I'm trying to write an application in NetBeans. I have a one Button called Ok which makes an array of buttons and all of them are connected to one actionListener. Here's the code:
public void actionPerformed(ActionEvent e) {
if (e.getSource() == Ok){
int a=500;
thread=new Thread[a];
Button button[]=new Button[a];
int z=0;
while (z<a){
button[z] = new Button();
button[z].setVisible(true);
button[z].setLabel("Generaed button");
Panel.add(button[z]);
z++;
}
z=0;
while (z<a){
cmp.putClientProperty(button[z], z);
button[z].addActionListener(this);
z++;}
}
if (e.getSource() != Ok){
value=cmp.getClientProperty(e.getSource());
int c = Integer.parseInt(value.toString());
thread[c] = new Thread() {
public void run() {
button[c].setLabel("test"); // <----This line is a problem.
}
};
thread[c].start();
}
}
The marked in code line causes Exception in thread "Thread-1" java.lang.NullPointerException.
I guess it's because that button is from another place in the code. I can put here a piece of code like:
Button button[]=new Button[amount];
button[c] = new Button();
and it doesn't return any exceptions no more but obviously it's not a solution.
How to get an access to button from code put in public void run()..
I will appreciate every advice.
Thanks