J2ME 文本字段异常
当我实例化一个文本字段时,我希望其中有一个数字作为默认文本。 问题是,我似乎无法将该值放入文本字段而不出现错误。 奇怪的是,我用同一个 TextField 来设置包含数字的变量的值。
TextField myTF = new TextField("Number", value, 10, TextField.NUMERIC);
当我运行此代码时,我收到一个异常,指出该值与 TextField.NUMERIC 的约束不匹配。 但是,当我检查变量值的值时,我得到以下输出:
value = 1234567890
value.length() = 10
该值由同一个 TextField 设置,保存到我正在使用的手机中,并且从手机设置加载时抛出异常。
When I instantiate a textField, I have a number in it that I want to be the default text. The problem is, I can't seem to be able to place that value into the textfield without getting an error. The strange thing about it is that the same TextField is what I use to set the value of the variable containing the number.
TextField myTF = new TextField("Number", value, 10, TextField.NUMERIC);
When I run this code, I receive an exception stating that value doesn't match the constraints of TextField.NUMERIC. However, when I check the vale of the value of the variable, I get the following output:
value = 1234567890
value.length() = 10
The value is set by the same TextField, saved to the phone that I am working on, and when loaded from the phone's settings, throws an exception.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这绝对是一个 JVM 错误。 如果
TextField
返回一个字符串,它必须能够接受它。 我唯一能建议的是稍微考虑一下场地的大小或限制。 您还没有指定您正在使用的设备,可能会有一些新的固件修复了错误。This is definitely a JVM bug. If a
TextField
returned a string, it must be able to accept it. The only thing I can advice is to play a bit with the size of the field or the constraints. You haven't specified the device you are using, there could be some new firmwares for it with bugfixes.解决您的问题的一个潜在解决方法可能是使用空值实例化该字段,然后设置文本。
a potential workaround to your problem could be to instantiate the field with a null value and then set the text afterwards.
我也有同样的问题。 手机尝试将字段值存储为 int ,最大 int 值是 (2^31) - 1 = 2,147,483,647,这比你(和我)需要的少了一位数。 解决方法是,将字段设置为文本类型并设置字符集 IS_LATIN_DIGITS。 干杯。
I have the same problem. The cellphone is trying to store the field value as an int, and the maximum int value is (2^31) - 1 = 2,147,483,647, which is one digit short of what you (and me) need. Workaround, make your field of type text and set a charset of IS_LATIN_DIGITS. Cheers.
我的想法是你尝试一下
My idea is you try it