
Originally Posted by
Tiger79
Maybe you might want to do some System.out.println within your :
for (i=1 ; i<list.size() ; i++ ) {
// It's okay here...
list.setFont(i, f);
}
just to check where it al goes wrong ?
Well, it makes sense why I can't apply font size here:
Code:
int i = 0;
for (Enumeration e = v.elements(); e.hasMoreElements(); i++ ) {
list.append((String)e.nextElement(), null);
// ArrayIndexOutOfBoundsException, if setting font here...
// list.setFont(i, f);
}
but I can here:
Code:
for (i=1 ; i<list.size() ; i++ ) {
// It's okay here...
list.setFont(i, f);
}
when we look at what makes the exception, when running the reload command. The only thing that happens in the reload scope, is we append an element to the list. That's not normally a problem, and if we comment out the list.setFont code, there is no problem appending another element. But if we use setFont first, and then append an element, we get the exception. So, in this code:
Code:
int i = 0;
for (Enumeration e = v.elements(); e.hasMoreElements(); i++ ) {
list.append((String)e.nextElement(), null);
// ArrayIndexOutOfBoundsException, if setting font here...
list.setFont(i, f);
}
the first element is appended successfully, and setFont will also apply font successfully, but next element will create an exception. I don't think it should, and I don't understand why, but it does. It is exactly what happens in the reload command scope:
Code:
public void commandAction (Command c, Displayable d) {
if (c == reloadcmd) {
// list.deleteAll();
// int i = 0;
// for (Enumeration e = v.elements(); e.hasMoreElements(); i++ ) {
// list.append((String)e.nextElement(), null);
// }
list.append("test", null);
// for (i=0 ; i<list.size() ; i++ ) {
// if (!list.getFont(i).equals(f)){
// list.setFont(i, f);
// }
// }
display.setCurrent(list);
}
Also shouldn't the variable i be initialised with 0 ?
Well, yes. It was only to show the diffedrence in font size.
Personally looking at your error I think something is going wrong here :
for (Enumeration e = v.elements(); e.hasMoreElements(); i++ ) {
list.append((String)e.nextElement(), null);
// ArrayIndexOutOfBoundsException, if setting font here...
// list.setFont(i, f);
}
you might want to do something like this :
Enumeration e = v.elements();
while( e.hasNextElement()
{
list.append((String)e.nextElement(), null);
// ArrayIndexOutOfBoundsException, if setting font here...
// list.setFont(i, f);
}
No, it's actually working well. It may be a little harder to read, but it does the same.