Skip to main content

ArrayIndexOutOfBoundsException when trying to add a component

2 replies [Last post]
Joined: 2009-10-11

Hello guys,
I'm trying something very simple here. I want to add a component to a form, but with index parameter.

form.addComponent(1, someLabel);

But it throws

- java.util.Vector.insertElementAt(), bci=20
- com.sun.lwuit.Container.insertComponentAt(), bci=65
- com.sun.lwuit.Container.addComponent(), bci=3

Any ideas why this is not working ?

Thank you in advance

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2007-07-12

> [b]form.addComponent(1, someLabel);[/b]
> Any ideas why this is not working ?

Yes - the form has no components (yet), the index "1" refers to a position beyond the (current) count of components within the form.

Always keep in mind, that index is zero-based, i.e. 0 designates the first child, 1 the second a.s.o.

More formally, index must be less than or equal to the count of children.

Joined: 2009-10-11

Yes I see. I though of that this morning actually. But too late. :)

Thank you and have a nice day !