Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
gottsc
Posts: 12
Registered: ‎10-31-2012
My Device: 9320, developer

Leading spaces cause EditField exception in 7.0?

I've encountered a problem whereby an EditField that's enclosed in a Manager encounters an exception. I can't find any reports of this by searching.

The exception occurs when around 4 leading spaces are added to a field. When the cursor leaves the field, the exception occurs in MathUtilities.clamp(). (This method was upgraded in 7.0 to throw an exception if the arguments are invalid; the exception text indicates that the lower bound is higher than the upper bound). On a simulator, the exception shows as a white-screen, but on my 7.1 device, the error manifests itself as not being able to enter a field that has the leading spaces.

It only seems to occur on OS greater than 7, and does not seem to occur in an EditField if it's not wrapped in a Manager. Only leading spaces cause the error; embedded spaces or trailing spaces don't do this. One or two leading spaces are OK, but three cause it in most of my tests.

I went back to basics and cut almost all the code out of our control with no luck, so I grabbed ArkadyZ's OneLineTextField sample code from
http://supportforums.blackberry.com/t5/Java-Development/Sample-Code-Scrollable-one-line-text-input-f...

I created a small app that has a single screen and the single field. If the field contains "   Init" (that's three leading spaces) the simulator gets this exception on clicking downarrow:
Thread [EditFieldTest(317)id=118176768] (Suspended (exception IllegalArgumentException))    
    MathUtilities.throwIAEForInvalidLowHigh(String, String) line: 456    
    MathUtilities.clamp(int, int, int) line: 46    
    XYRect.intersect(XYRect) line: 352    
    EditField(TextField).getFocusRectPhantom(XYRect) line: 8091    
    EditField(TextField).invalidateFocusImmediately() line: 2708    
    EditField(TextField).scrollVertically(int) line: 6618    
    EditField(TextField).moveFocus(int, int, int) line: 7549    
    HorizontalFieldManager(Manager).moveFocusOrScroll(Adjustment, int, int) line: 2735    
    OneLineTextField(Manager).moveFocusOrScroll(Adjustment, int, int) line: 2732    
    VerticalFieldManager(Manager).moveFocusOrScroll(Adjustment, int, int) line: 2732    
    TitleStatusManager(Manager).moveFocusOrScroll(Adjustment, int, int) line: 2732    
    Screen$NavigationMovementFocusSelector.select() line: 6727    
    HelloBlackBerryScreen(Screen).doScrollOrFocusMove(int, int, Screen$ScrollingFocusSelector) line: 5927    
    HelloBlackBerryScreen(Screen).navigationMovement(int, int, int, int) line: 7195    
    HelloBlackBerryScreen(Screen).dispatchNavigationEvent(NavigationEvent) line: 1731    
    UiEngineImpl.processMessage(Object, Message, boolean) line: 4211    
    HelloBlackBerry(Application).doProcessNextMessage(Message) line: 2790    
    HelloBlackBerry(Application).processNextMessage(Message, boolean) line: 1921    
    HelloBlackBerry(Application).enterEventDispatcher() line: 1709    
    HelloBlackBerry.main(String[]) line: 19    

Here's ArkadyZ's code if you want to replicate.

package mypackage;

import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.HorizontalFieldManager;

public class OneLineTextField extends HorizontalFieldManager {
    private EditField _editField;

    public OneLineTextField(String label, String initialValue, int maxChars, long style) {
        super(NO_HORIZONTAL_SCROLL);
        HorizontalFieldManager textMgr = new HorizontalFieldManager(HORIZONTAL_SCROLL);
        add(new LabelField(label));
        _editField = new EditField("", initialValue, maxChars, style | EditField.NO_NEWLINE | EditField.FOCUSABLE | EditField.EDITABLE);
        textMgr.add(_editField);
        add(textMgr);
    }

    public String getText() {
        return _editField.getText();
    }
}

Add a field to your screen like so:
        OneLineTextField aTestTextField = new OneLineTextField("Label: ", "Init", 40, 0);
        add(aTestTextField);

So here are my questions: Is anyone else experiencing anything like this? Is the sample code incorrect in some way? The problem seems to be specific to the kind of code I've shown. Other apps I've created that don't use this exact type of manager-wrapping don't crash. It would be interesting to have people try out their apps with some leading spaces.

Any thoughts? Is this an OS bug? Thanks!

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Leading spaces cause EditField exception in 7.0?

looks like a bug to me, you could report it on jira.
maybe you can wrap a try/catch around the offending method as a workaround.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Contributor
gottsc
Posts: 12
Registered: ‎10-31-2012
My Device: 9320, developer

Re: Leading spaces cause EditField exception in 7.0?

Reported  in JIRA (JAVAAPI-2347). I had to use a new user ID since JIRA redirects in a loop with my regular user ID.

 

I don't believe there is any way to catch since the exception happens on the event queue.

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Leading spaces cause EditField exception in 7.0?

you should be able to wrap try/catch around the getResource calls, i did that successfully.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter