3

当我使用 Java Wireless 工具包运行我的 midlet 时,midlet 运行正确,但是当它尝试解析文本字段时,出现以下错误;

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)

问题是什么?

我正在使用 JWT 2.5.2_01

4

2 回答 2

3

问题解决了。

正如 McDowell 之前提到的,问题在于编码设置。克服这个问题的最好方法是从 WTK 声明编码信息。

在您的工作目录中,找到 ktools.properties 文件(我的机器上的“workdir\wtklib\ktools.properties”或“workdir\wtklib\Linux\ktools.properties”)。并添加以下行:

microedition.encoding= *encoding*

对于 ASCII 编码:

microedition.encoding=ISO8859_1

这将完成这项工作(:

于 2010-01-26T09:29:36.200 回答
2

我猜这是因为你要么是:

  • 使用String(byte[])构造函数(通常应避免使用此构造函数)
  • 错误地使用String(byte[], String)构造函数

在这两种情况下,您都将使用错误的编码将字节数据解码为字符数据,这是一种字节值10010111非法的编码(至少作为第一个字节)。

任何从byte数据到char数据的转换(例如创建字符串)都将涉及将数据从“某种其他编码”转换为 UTF-16。在执行此转换之前,您需要知道并指定“其他编码”是什么。

于 2010-01-25T15:21:41.083 回答