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
Developer
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

BrowserField refresh throwing IllegalStateException

Hi all,

 

I am working on 5.0.

I am using BrowserField in my app to load an URL. while refrehsing the content it is throwing illegalstateexception.

 

anybody have any ideas regarding this??

 

the following is the code

 

 

btnRefresh.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
try
{
// throwingException browser.refresh();
}catch(Exception e)
{
Tools.print("XCO:MyBrowserFieldScreen:Refresh: Error" + e.toString());
}
}
});

 

 

 

Thanks and Regards,
PraveenGoparaju.
Developer
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: BrowserField refresh throwing IllegalStateException

While debugging i found that an error is throwing at the line

 

BrowserField.deleteAll();

 

actually am not adding any fields to browser. But somehow it is throwing me error, while calling

 

browser.refresh();

 

browser.forward();

 

browser.back();

 

methods..

Thanks and Regards,
PraveenGoparaju.
Developer
Posts: 16,652
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: BrowserField refresh throwing IllegalStateException

maybe an eventlock problem? what is the detail message of the exception?

try to run it in an invokelater.

----------------------------------------------------------
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
Developer
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: BrowserField refresh throwing IllegalStateException

Thanks simon,

 

am calling this browserfield screen in eventlock.

 

the following is the error msg:

XCO:MyBrowserFieldScreen:Refresh: Errorjava.lang.IllegalStateException: tried to remove FieldWithFocus

 

actually am placing the browser.refresh() in try/catch, still a simulator crash is happening and when i click on "continue"  the control is back to app.

 

i will try with invokelater and let you know the latest result.

Thanks and Regards,
PraveenGoparaju.
Developer
Posts: 16,652
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: BrowserField refresh throwing IllegalStateException

i know the "delete field with focus" error. try to set the focus on one of your own fields before executing deleteAll

----------------------------------------------------------
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
Developer
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: BrowserField refresh throwing IllegalStateException

actually the focus is on a custom button.

 

i have back, next, refresh as custom buttons and am calling the browser.back(), browser.refresh() in their fieldChangeListeners.

 

am not at all trying to delete any field while refreshing/back/next. so can you tell a litle more over

"try to set the focus on one of your own fields before executing deleteAll"

Thanks and Regards,
PraveenGoparaju.
Developer
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: BrowserField refresh throwing IllegalStateException

[ Edited ]

 

Hi simon,

 

i tried with what you said. i removed the eventlock while pushing the screen and now pushing the screen in the invokelater... still the same problem.

 

the following is the code

 

 

UiApplication.getUiApplication().invokeLater(new Runnable()
				{
					public void run()
					{
						MyBrowserFieldScreen screen = new MyBrowserFieldScreen(clikthruURL);
						TransitionContext transitionContextIn = new TransitionContext(TransitionContext.TRANSITION_SLIDE);
				        transitionContextIn.setIntAttribute(TransitionContext.ATTR_DURATION, 300);
				        transitionContextIn.setIntAttribute(TransitionContext.ATTR_DIRECTION, TransitionContext.DIRECTION_UP);              
				         
				        TransitionContext transitionContextOut = new TransitionContext(TransitionContext.TRANSITION_SLIDE);
				        transitionContextOut.setIntAttribute(TransitionContext.ATTR_DURATION, 300);
				        transitionContextOut.setIntAttribute(TransitionContext.ATTR_DIRECTION, TransitionContext.DIRECTION_DOWN);                                                            
				        transitionContextOut.setIntAttribute(TransitionContext.ATTR_KIND, TransitionContext.KIND_OUT);                
				                          
				        UiEngineInstance engine = Ui.getUiEngineInstance();
				        
				        engine.setTransition(null, screen, UiEngineInstance.TRIGGER_PUSH, transitionContextIn);
				        engine.setTransition(screen, null, UiEngineInstance.TRIGGER_POP, transitionContextOut);
				        
						UiApplication.getUiApplication().pushScreen(screen);
					}
				});

 

 

Thanks and Regards,
PraveenGoparaju.
Developer
Posts: 19,624
Registered: ‎07-14-2008
My Device: Not Specified

Re: BrowserField refresh throwing IllegalStateException

I have had similar problems with BrowserField, which I "fixed" by setting the focus back on the BrowserField before doing an action on it.  Try that. 

Developer
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: BrowserField refresh throwing IllegalStateException

working peter!!!

thanks!!

 

thanks simon.

 

once again thankU peter!!

 

but when i did a monkey testing on refresh button, it crashed throwing the same error!!


JVM error: 104

uncaught: IllegalStateException:

 

can you tell me why it is happening??

Thanks and Regards,
PraveenGoparaju.
Developer
Posts: 19,624
Registered: ‎07-14-2008
My Device: Not Specified

Re: BrowserField refresh throwing IllegalStateException

Refresh button?

 

Just to confirm, my code looks like

browserField.setFocus(); // Overcome random BrowserField bug

browserField.refresh();