could someone explain to me why the following results in a Null pointer Exception? And how to set a value for bitarray[0]?
BitSet[] bitarray;
bitarray= new BitSet[10];
bitarray[0].set(1);
Also, why something like this work and not result in a pointer exception?
BitSet[] bitarray = new BitSet[10];
BitSet bits = new BitSet(32);
bits.set(1);
bitarray[0] = bits;
Thanks
You can find nice help on Arrays Tutorial
In case of above example if you just declare array of
10 BitSetbecause defualt value ofBitSetisnullso it contains allnullreferencesSo initialize the reference you need to do