Not being familiar with the behavior of every class mentioned here, I can't tell you precisely what's happening, but basically, I can tell you that the "set" method lets you set an element that already has a value. You can't set element 0 of a zero-element Vector, because there is no element 0 yet.
works fine, because I'm using set() to change an element, not to add a new one. To add an element to an empty Vector, you have to use "add", not "set". Alternatively, you can use setSize() to fill the Vector with a certain number of null elements, then use set() to give them values.