3

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

gnat
  • 6,213
  • 108
  • 53
  • 73
Mp0int
  • 18,172
  • 15
  • 83
  • 114
  • Could you post the code you are using to read the value from the textfield? That would probably more use than the stack trace. – James Goodwin Jan 25 '10 at 15:19
  • Unfortunately, i do nor have the code, but just the jar file. I am running jar on JWT. Some googling show me this porblem was related to jvm encoding. How can i check and change encoding settings of JVM? – Mp0int Jan 25 '10 at 15:24

2 Answers2

3

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 (:

Mp0int
  • 18,172
  • 15
  • 83
  • 114
2

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
  • 107,573
  • 31
  • 204
  • 267
  • 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 :S How can i do this on Linux? – Mp0int Jan 25 '10 at 16:41
  • @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 Jan 25 '10 at 17:08