views:

485

answers:

3

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.

A: 

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.

Malcolm
A: 

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);
akf
A: 

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.