J2ME 文本字段异常

发布于 2024-07-26 16:27:34 字数 417 浏览 9 评论 0原文

当我实例化一个文本字段时,我希望其中有一个数字作为默认文本。 问题是,我似乎无法将该值放入文本字​​段而不出现错误。 奇怪的是,我用同一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

软糯酥胸 2024-08-02 16:27:34

这绝对是一个 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.

放血 2024-08-02 16:27:34

解决您的问题的一个潜在解决方法可能是使用空值实例化该字段,然后设置文本。

TextField myTF = new TextField("Number", null, 10, TextField.NUMERIC);
myTF.setString(value);

a potential workaround to your problem could be to instantiate the field with a null value and then set the text afterwards.

TextField myTF = new TextField("Number", null, 10, TextField.NUMERIC);
myTF.setString(value);
柒夜笙歌凉 2024-08-02 16:27:34

我也有同样的问题。 手机尝试将字段值存储为 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.

猫七 2024-08-02 16:27:34

我的想法是你尝试一下

String str=""+value;
TextField myTF = new TextField("Number",str,10,TextField.NUMERIC);

My idea is you try it

String str=""+value;
TextField myTF = new TextField("Number",str,10,TextField.NUMERIC);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文