BlackBerry Forums Support Community

BlackBerry Forums Support Community (http://www.blackberryforums.com/)
-   Developer Forum (http://www.blackberryforums.com/developer-forum/)
-   -   IllegalArgumentException on PopScreen (http://www.blackberryforums.com/developer-forum/223468-illegalargumentexception-popscreen.html)

behrk2 04-03-2010 01:23 PM

IllegalArgumentException on PopScreen
 
Hi Everyone,

When I try to close a Screen, I am receiving an IllegalStateException.

What I have noticed, however, is that when I push this screen and then close out of it (pop), it works fine. However, if I push the screen, click on one of the buttons on my screen, and then close out of the screen, I receive the IllegalStateException. This is even true if I click on a button that does not have a fieldchangelistener associated with it.

Here is my stack trace:

Code:

Thread [KFlicks(228)id=319047680] (Suspended (exception IllegalStateException))       
        Search2Screen(Screen).close() line: 579       
        Search2Screen(Screen).onClose() line: 3700       
        Search2Screen(Screen).keyCharUnhandled(char, int, int) line: 3017       
        Search2Screen(MainScreen).keyCharUnhandled(char, int, int) line: 320       
        Search2Screen(Screen).dispatchKeyEvent(IKeyEvent) line: 697       
        Search2Screen(Screen).processKeyEvent(IKeyEvent) line: 3422       
        UiEngineImpl.processMessage(Object, Message, boolean) line: 3587       
        Application(Application).doProcessNextMessage(Message) line: 2252       
        Application(Application).processNextMessage(Message) line: 1516       
        Application(Application).enterEventDispatcher() line: 1357       
        Application.main(String[]) line: 28

On "Search2Screen(Screen).close() line: 579", UIEngine = Null

Can anyone offer me any help? Thanks!

jacob.tabak 04-03-2010 03:46 PM

Hi,

The subject of your post says illegal argument exception and the body of your post says illegal state exception. I'm going to assume your problem is illegal state exception. You will encounter this exception a lot you're not familiar with the concept of the event thread.

This article explains it pretty well: BlackBerry UI Threading - The Very Basics - Thinking BlackBerry

Basically, when you launch your application, you probably use the UiApplication.enterEventDispatcher() method. Whichever thread this method is called on becomes the event thread, and it is the only thread that is allowed to directly modify the UI of your application.

If you attempt to modify the UI from a different thread, you'll receive an illegal state exception.

The way to overcome this problem is to use the following technique:
Code:

UiApplication.getUiApplication().invokeLater(new Runnable() {
    public void run() {
        //your UI code here
    }
});

I typed that from memory so there may be syntax errors, but look at the examples on thinkingblackberry.


All times are GMT -5. The time now is 02:35 AM.

Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.