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
Highlighted
Developer
Posts: 87
Registered: ‎02-20-2011
My Device: Not specified

BrowserFieldErrorHandler InterruptedIOException

Hi, I try use BrowserField and BrowserFieldErrorHandler to notify error message to user if  something wrong like code below :

 

public class BrowserScreen extends MainScreen {
	private BrowserField browserField;
	private BrowserFieldConfig browserFieldConfig;
	private ButtonField okButton;
	
	public BrowserScreen() {
		okButton = new ButtonField("Go");
		okButton.setChangeListener(new FieldChangeListener() {
			
			public void fieldChanged(Field field, int context) {
				browserField.requestContent("http://www.google.com");
			}
		});
		
		add(okButton);
		
		ConnectionFactory connFactory = createCustomConnectionFactory();
		
		
		browserFieldConfig = new BrowserFieldConfig();
		browserFieldConfig.setProperty(BrowserFieldConfig.CONNECTION_FACTORY, connFactory);
		
		browserField = new BrowserField(browserFieldConfig);
		
		browserField.getConfig().setProperty(BrowserFieldConfig.ERROR_HANDLER, new MyBrowserFieldErrorHandler(browserField));
		
		add(browserField);
		
	}
	
	private void displayError(String message){
		synchronized (Application.getEventLock()) {
			Dialog.ask(Dialog.OK, message);
		}
	}
	
	private ConnectionFactory createCustomConnectionFactory(){
		ConnectionFactory factory = new ConnectionFactory();
		factory.setConnectionTimeout(5000);
		
		return factory;
	}
	
	private class MyBrowserFieldErrorHandler extends BrowserFieldErrorHandler {	
		public MyBrowserFieldErrorHandler(BrowserField bf) {
			super(bf);
		}
		
		public void displayContentError(String url, String errorMessage) {
			displayError(errorMessage);
		}
		
		public void displayContentError(String url, InputConnection connection, Throwable t) {
			displayError(t.getMessage());
		}
		
		public void requestContentError(BrowserFieldRequest request, Throwable t) {
			displayError(t.getMessage());
		}
		
		public void navigationRequestError(BrowserFieldRequest request, Throwable t) {
			displayError(t.getMessage());
		}
		
		public BrowserField getBrowserField(){
			return super.getBrowserField();
		}
	}	
}

 

First,, click OK button and can access google with properly, Try to simulate error condition with pull out LAN cable, click some link in google site. I got error Uncaught: InterruptedIOException, click continue and show Dialog box "Local connection timeout after ~5000"

 

Question is how to eliminate InterruptedIOException Error and only show Error Message Local connection timeout after ~5000

 

Thanks


------------------------------------------------------------------------------------------
1. Feel free to press the like button on the right side to thank the user that helped you.
2. Please mark posts as solved if you found a solution.