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
Regular Contributor
Posts: 55
Registered: ‎09-01-2010
My Device: Not Specified
Accepted Solution

Uncaught IllegalStateException

I want to add previous and forward button to controll the 'BrowserField'  in my app. But often it is giving "JVM 104 error: uncaught IllegalStateException" for the statement 'browserFieldHistory.goBack()' and also for "browserFieldHistory.goForward()"

 

private final class ButtonListener implements FieldChangeListener {
        public void fieldChanged(Field field, int context) {

           ........

           if(field == BackButton)  // back
           {
               try {
                browserFieldHistory = getBrowserField().getHistory();
                if(browserFieldHistory.canGoBack())
                {
                    try {
                        browserFieldHistory.goBack();
                    } catch (IllegalStateException e){
                        Log.info("Error executing js:back(): ");
                    }
                }
               } catch(IllegalStateException e){                        
                    Log.info("Error executing js:back(): ");
               }
           }
           if(field == ForwardButton) // forward
           {
               try{
                    browserFieldHistory = getBrowserField().getHistory();
                    if(browserFieldHistory.canGoForward())
                    {
                        try {
                            browserFieldHistory.goForward();  
                        } catch(IllegalStateException e) {
                        }
                    }                                                 
               } catch(IllegalStateException e) {                        
                    Log.info("Error executing js:next(): ");
               }
           }
        }
    }

 

    Although both of the statement are in the "try-catch" with IllegalStateException handling, still it is throwing uncaught exception. Can anyone point out the error in my code?

Developer
Posts: 19,612
Registered: ‎07-14-2008
My Device: Not Specified

Re: Uncaught IllegalStateException

As an experiment, set the focus on the BrowserField before you do this.

 

                    try {
                        browserFieldHistory.setFocus();

                        browserFieldHistory.goBack();
                   

New Contributor
Posts: 9
Registered: ‎01-18-2011
My Device: Not Specified

Re: Uncaught IllegalStateException

Thanks Peter. It works perfectly fine.

New Developer
Posts: 2
Registered: ‎01-21-2013
My Device: Developer

Re: Uncaught IllegalStateException

[ Edited ]

Thanks for the solution.I think you meant to set focus for "BrowserField" object rather "BrowserFieldHistory". 

Developer
Posts: 19,612
Registered: ‎07-14-2008
My Device: Not Specified

Re: Uncaught IllegalStateException

Opps, you are correct!