views:

329

answers:

2

When i run my midlet with Java Wireless toolkit, midlet runs correctly, but when it try to parse a textfield, following error occurs;

java.lang.RuntimeException: IOException reading reader invalid first byte 10010111
    at com.sun.cldc.i18n.Helper.byteToCharArray(+228)
    at com.sun.cldc.i18n.Helper.byteToCharArray(+9)
    at java.lang.String.<init>(+7)
    at z.a(+219)
    at z.a(+103)
    at DP4JPhone.a(+74)
    at DP4JPhone.a(+115)
    at DP4JPhone.commandAction(+120)
    at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(+282)
    at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(+10)
    at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(+68)
    at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(+47)
    at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.handleVmEvent(+186)
    at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+57)

What is the problem?

I am using JWT 2.5.2_01

+2  A: 

I would guess that it is because you are either:

  • using the String(byte[]) constructor (this constructor should generally be avoided)
  • using the String(byte[], String) constructor incorrectly

In both cases, you would be decoding byte data to character data using the wrong encoding, an encoding where the byte value 10010111 is illegal (at least, as a first byte).

Any conversion from byte data to char data (such as the creation of a String) will involve the transformation of data from "some other encoding" to UTF-16. You need to know and specify what that "some other encoding" is prior to performing this transformation.

McDowell
I do not have the code; but as far as i know, the encoding must be ISO-8859-1. But settings shows that my encoding is UTF-8... Since i do not hava a chance to change encoding of the files, i must change the JVM encodin (as far as i understand from google search results). But i do not know how to accomplish this on linux :SHow can i do this on Linux?
FallenAngel
@mp0int - That's a pity, because changing either the code or the file is the correct solution. Java does not have a supported mechanism for setting the default encoding except via the operating system. If you are desperate, you can try setting the `file.encoding` property on the command line, but be aware that this might have unintended consequences: http://bugs.sun.com/view_bug.do?bug_id=4163515
McDowell
+1  A: 

Problem Solved.

As McDowell mentioned before, problem was about encoding settings. Best way to overcome this problem is declaring encoding info from WTK.

Within your working directory, find ktools.properties file ('workdir\wtklib\ktools.properties' or 'workdir\wtklib\Linux\ktools.properties' as is on my machine). And add the following lines:

microedition.encoding= *encoding*

For ASCII encoding:

microedition.encoding=ISO8859_1

That will do the job (:

FallenAngel