Hi,
Say I have a 2 dimensional byte array appendixBlock[10][] & another 1
dimensional byte array, say, tempBytes[].
I do this in the code:
String tempString = new
String(((String)object).getBytes(), "UTF-16");
byte[] tempBytes = tempString.getBytes();
bytesNum = tempBytes.length;
appendixBlock[appendixIndex] = null;
for(int x=0; x<bytesNum;x++)
{
appendixBlock[appendixIndex][x] = tempBytes[x];
}
Am getting NullPointer Exception due to the above. Whereas if I do:
appendixBlock[appendixIndex] = tempBytes;
am not getting any exception. Can anyone please throw some light on
what's wrong?
Jussi Piitulainen - 08 Oct 2006 15:24 GMT
> I do this in the code:
...
> appendixBlock[appendixIndex] = null;
> for(int x=0; x<bytesNum;x++)
[quoted text clipped - 3 lines]
>
> Am getting NullPointer Exception due to the above. Whereas if
You shouldn't be too surpised to find that
appendixBlock[appendixIndex] is null just after
you explicitly set it so.
Set it to a new byte[bytesNum] instead.
Arne Vajhøj - 08 Oct 2006 17:13 GMT
>> appendixBlock[appendixIndex] = null;
>> for(int x=0; x<bytesNum;x++)
[quoted text clipped - 9 lines]
>
> Set it to a new byte[bytesNum] instead.
Sounds as a plan !
:-)
And after than, then using System.arraycopy could
get rid of the for loop.
Arne