Hi ,
I got a problem. I want to display arratlist values in buttons. ie.there are 9 buttons. I want to display the buttons names from that arraylist. suppose in the list I have 2 4 5 6. I want to diaplay on the button 1 the value 2. on button 2 the value 4. & so on..
But I am getting java.lang.ClassCastException in the line button.setLabel( (String) a); .what should i do.
the code is:-
for (int i=0; i<9; i++) {
button = new Button();
this.add(button);
}
ArrayList arraylist = new ArrayList();
while (true) {
Random random = new Random();
int randomno = random.nextInt( 10);
boolean flag = false;
for (int j = 0; j < (arraylist.size()); j++) {
Integer integer =(Integer) arraylist.get(j);
int randomvalue=integer.intValue();
if (randomvalue == randomno) {
flag = true;
}
}
if (!flag) {
arraylist.add(new Integer(randomno));
}
if (arraylist.size() == 10) {
break;
}
}
for( int j=0,i=0; j<arraylist.size(); j++,i++) {
Object a = arraylist.get(j);
System.out.println("a= " +a);
button.setLabel( (String) a);
System.out.println("List " +arraylist.get(j));
}
}