java.lang.RuntimeException: IOException reading reader null

Hi,

I am recieving:

java.lang.RuntimeException: IOException reading reader null

at com.sun.cldc.i18n.Helper.byteToCharArray(+169)

at java.lang.String.<init>(+9)

at java.lang.String.<init>(+9)

at ApplicationLayer.Actions.Accessories.CommunicateUtil.communicate(+228)

when I am calling: new String(receivedData,"UTF16");

recievedData is byte[] that contains UNICODE bytes (two bytes for each character).

What is wrong?

[489 byte] By [naor_ya] at [2007-10-2 5:37:37]
# 1

Here's the list of charsets supported by Java (1.4):

http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html

You'll notice it doesn't contain "UTF16" in the list. It does contain "UTF-16" though. Although I'm surprised you don't get an UnsupportedEncodingException instead of what you did get.

DrClapa at 2007-7-16 1:48:06 > top of Java-index,Java Essentials,Java Programming...
# 2

Moreover, sometimes it did work and after 2 or 3 uses of this line the exception accures.

I tried as you said UTF-16 but I got the same error.

I wrote this function in order to bypass the error:

private static String toUTF16(byte[] bytes) {

char chars[]=new char[bytes.length/2];

int index=0;

for (int i=0;i<bytes.length;i=i+2) {

short high=(short)(0xFF & bytes[i]);

short low=(short)(0xFF & bytes[i+1]);

short left=(short)(high<<8);

short k=(short)(left | low);

char value=(char)k;

chars[index]=value;

index++;

}

return new String(chars);

}

What do you think?

and what do you think was the error?

Thanks, Naor.>

naor_ya at 2007-7-16 1:48:06 > top of Java-index,Java Essentials,Java Programming...
# 3
jump
naor_ya at 2007-7-16 1:48:06 > top of Java-index,Java Essentials,Java Programming...