Tuesday, March 5, 2013

Java and it's inherent stupidity(Textfield-a case study)

That monkey called James Gosling needs to be shot off the tree that he's hanging!

The monkies who designed java and it's implementation fucked again! Spent the whole night debugging Textfield which throws an incomprehensible Uncaught exception java/lang/IllegalArgumentException.
This is because the value being passed is greater than the (compulsory)defined size of the Item.
new TextField("Group Name", name, 10, TextField.ANY);
Now, you might be tempted here to get the maxSize() for TextField, but the values am getting are stupid platform suggestions that make no sense(i.e 12). So because I know any device capable of installing Saya is also capable of holding at least 100 chars in a text field, I hardcoded the limit to such
new TextField("Group Name", name, 100, TextField.ANY);
But also was careful enough to make sure the dynamic content being inserted there(i.e name) does not exceed the limit.

if(name.length()>99){
                    name = name.substring(0, 99);
                }

http://jcs.mobile-utopia.com/jcs/67140_TextField.html
public class TextField extends Item
TextField is an editable text component that may be placed into a {@link Form Form}. It can be given a piece of text that is used as the initial value.

TextField has a maximum size, which is the maximum number of characters that can be stored in the object at any time (its capacity). This limit is enforced when the TextField instance is constructed, when the user is editing text within the TextField, as well as when the application program calls methods on the TextField that modify its contents. The maximum size is the maximum stored capacity and is unrelated to the number of characters that may be displayed at any given time. The number of characters displayed and their arrangement into rows and columns are determined by the device.

The implementation may place a boundary on the maximum size, and the maximum size actually assigned may be smaller than the application had requested. The value actually assigned will be reflected in the value returned by {@link #getMaxSize() getMaxSize()}. A defensively-written application should compare this value to the maximum size requested and be prepared to handle cases where they differ.

No comments:

Post a Comment