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
Posts: 28
Registered: ‎02-13-2010
My Device: 9000
My Carrier: Fido

RuntimeException with pushModalScreen()

I was following the code sample here and playing around with it. I received a RuntimeException when I changed the constructor for PleaseWaitDemoScreen a bit, and have no idea why.

 

The _waitScreen.show() method works perfectly fine inside the ButtonField's fieldChanged method. However, when I pulled it out of the button I got the RuntimeException (I pulled it out because I wanted the progress loading to start as soon as I push the PleaseWaitDemoScreen, and not after a button press). It seems that pushModalScreen() is breaking the code. I've tried app.invokeLater(new Runnable()) method and sychchronize with the eventlock, but the Exception is still there.

 

Any help would be appreciated. Thank you.

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: RuntimeException with pushModalScreen()

Can you tell us which exception is being thrown, and at what line of code (include a snippet)?

 

 

Contributor
Posts: 28
Registered: ‎02-13-2010
My Device: 9000
My Carrier: Fido

Re: RuntimeException with pushModalScreen()

[ Edited ]

Here's what I did.

 

I changed the constructor for PleaseWaitDemoScreen from:

 

public PleaseWaitDemoScreen() {
        this.setTitle("PleaseWaitDemo");
        ButtonField startButton = new ButtonField("Start", ButtonField.FIELD_HCENTER | ButtonField.CONSUME_CLICK);
        startButton.setChangeListener( new FieldChangeListener() {
            public void fieldChanged(Field field, int context) {
                _waitScreen = new PleaseWaitPopupScreen("Please wait", "Wating for test Thread", "dummy URL, not actually used");
                int result = _waitScreen.show();
                _resultField.setText("Result: " + Integer.toString(result));
            }
        });
        this.add(startButton);
        this.add(_resultField);
}

 To:

 

public PleaseWaitDemoScreen() {
        this.setTitle("PleaseWaitDemo");
        _waitScreen = new PleaseWaitPopupScreen("Please wait", "Wating for test Thread", "dummy URL, not actually used");
        int result = _waitScreen.show();
        _resultField.setText("Result: " + Integer.toString(result));
        this.add(_resultField);
}

 

And the code throws a RuntimeException. The exact line of the exception is in PleaseWaitPopupScreen's show() method, on this line:

 

UiApplication.getUiApplication().pushModalScreen(this);

 

I tried the following fix for the above line:

 

UiApplication.getUiApplication().invokeLater(new Runnable() {
        public void run() {
                UiApplication.getUiApplication().pushModalScreen(this);
        }
});

 

But the same RuntimeException persisted. Why would the same method work when called inside a ButtonField's fieldChanged method, but not when called directly from the current Screen?

 

Thanks for your fast reply.

 

 

 

 

Highlighted
Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: RuntimeException with pushModalScreen()

Again, what is the exception? "Runtime exception" is meaningless. There are many.

 

It's hard to say looking at this one snippet, but I'm guessing that you have not yet entered the event dispatcher when this constructor is called. In this case, you would be getting some type of illegal state exception.

 

The reason it works in the listener is that the listener is only called as a result of some UI event, which means there is no way for it to be called until/unless the program is in the event dispatcher.