Question

I am new in BB programming.trying to open google url inside the application.Whe I tested in

simulator 9900, it showing an error as follows:

RenderingSession#getBrowserContent() threw RenderingException

RenderingSession#getBrowserContent() threw net.rim.device.api.browser.field.RenderingException: IOException in connection

I have enabled MDS-CS.But still i am getting this problem.

The code is as follows ie the sample given by BB.

public final class BrowserFieldDemo extends UiApplication implements RenderingApplication 
{

    private static final String REFERER = "referer";  

    private RenderingSession _renderingSession;   
    private HttpConnection  _currentConnection;
    private MainScreen _mainScreen;


    /**
     * Entry point for application
     * @param args Command line arguments (not used)
     */
    public static void main(String[] args) 
    {
        BrowserFieldDemo app = new BrowserFieldDemo();

        // Make the currently running thread the application's event
        // dispatch thread and begin processing events.
        app.enterEventDispatcher();
    }

    /**
     * Creates a new BrowserFieldDemo object
     */
    public BrowserFieldDemo() 
    {       
        _mainScreen = new MainScreen(Screen.HORIZONTAL_SCROLL);        
        pushScreen(_mainScreen);
        _renderingSession = RenderingSession.getNewInstance();

        // Enable javascript
        //_renderingSession.getRenderingOptions().setProperty(RenderingOptions.CORE_OPTIONS_GUID, RenderingOptions.JAVASCRIPT_ENABLED, true);                        

        PrimaryResourceFetchThread thread = new PrimaryResourceFetchThread("http://www.google.com", null, null, null, this);
        thread.start();            
    }

    /**
     * Processes an http connection
     * 
     * @param connection The connection to the web content
     * @param e The event triggering the connection
     */
    void processConnection(HttpConnection connection, Event e) 
    {
        // Cancel previous request
        if (_currentConnection != null) 
        {
            try 
            {
                _currentConnection.close();
            } 
            catch (IOException e1) 
            {                
            }
        }

        _currentConnection = connection;

        BrowserContent browserContent = null;

        try 
        {
            browserContent = _renderingSession.getBrowserContent(connection, this, e);

            if (browserContent != null) 
            {
                Field field = browserContent.getDisplayableContent();

                if (field != null) 
                {
                    synchronized (Application.getEventLock()) 
                    {
                        _mainScreen.deleteAll();
                        _mainScreen.add(field);
                    }
                }

                browserContent.finishLoading();
            }

        } 
        catch (RenderingException re) 
        {
            Utilities.errorDialog("RenderingSession#getBrowserContent() threw " + re.toString());
        } 
        finally 
        {
            SecondaryResourceFetchThread.doneAddingImages();
        }

    }    

    /**
     * @see net.rim.device.api.browser.field.RenderingApplication#eventOccurred(Event)
     */
    public Object eventOccurred(Event event) 
    {
        int eventId = event.getUID();

        switch (eventId) 
        {
            case Event.EVENT_URL_REQUESTED : 
            {
                UrlRequestedEvent urlRequestedEvent = (UrlRequestedEvent) event;    

                PrimaryResourceFetchThread thread = new PrimaryResourceFetchThread(urlRequestedEvent.getURL(),
                                                                                         urlRequestedEvent.getHeaders(), 
                                                                                         urlRequestedEvent.getPostData(),
                                                                                         event, this);
                thread.start();

                break;

            } 
            case Event.EVENT_BROWSER_CONTENT_CHANGED: 
            {                
                // Browser field title might have changed update title.
                BrowserContentChangedEvent browserContentChangedEvent = (BrowserContentChangedEvent) event; 

                if (browserContentChangedEvent.getSource() instanceof BrowserContent) 
                { 
                    BrowserContent browserField = (BrowserContent) browserContentChangedEvent.getSource(); 
                    String newTitle = browserField.getTitle();
                    if (newTitle != null) 
                    {
                        synchronized (getAppEventLock()) 
                        { 
                            _mainScreen.setTitle(newTitle);
                        }                                               
                    }                                       
                }                   

                break;                

            } 
            case Event.EVENT_REDIRECT : 
            {
                RedirectEvent e = (RedirectEvent) event;
                String referrer = e.getSourceURL();

                switch (e.getType()) 
                {  
                    case RedirectEvent.TYPE_SINGLE_FRAME_REDIRECT :
                        // Show redirect message.
                        Application.getApplication().invokeAndWait(new Runnable() 
                        {
                            public void run() 
                            {
                                Status.show("You are being redirected to a different page...");
                            }
                        });

                    break;

                    case RedirectEvent.TYPE_JAVASCRIPT :
                        break;

                    case RedirectEvent.TYPE_META :
                        // MSIE and Mozilla don't send a Referer for META Refresh.
                        referrer = null;     
                        break;

                    case RedirectEvent.TYPE_300_REDIRECT :
                        // MSIE, Mozilla, and Opera all send the original
                        // request's Referer as the Referer for the new
                        // request.
                        Object eventSource = e.getSource();
                        if (eventSource instanceof HttpConnection) 
                        {
                            referrer = ((HttpConnection)eventSource).getRequestProperty(REFERER);
                        }

                        break;
                    }

                    HttpHeaders requestHeaders = new HttpHeaders();
                    requestHeaders.setProperty(REFERER, referrer);
                    PrimaryResourceFetchThread thread = new PrimaryResourceFetchThread(e.getLocation(), requestHeaders,null, event, this);
                    thread.start();
                    break;

            } 
            case Event.EVENT_CLOSE :
                // TODO: close the appication
                break;

            case Event.EVENT_SET_HEADER :        // No cache support.
            case Event.EVENT_SET_HTTP_COOKIE :   // No cookie support.
            case Event.EVENT_HISTORY :           // No history support.
            case Event.EVENT_EXECUTING_SCRIPT :  // No progress bar is supported.
            case Event.EVENT_FULL_WINDOW :       // No full window support.
            case Event.EVENT_STOP :              // No stop loading support.
            default :
        }

        return null;
    }

    /**
     * @see net.rim.device.api.browser.field.RenderingApplication#getAvailableHeight(BrowserContent)
     */
    public int getAvailableHeight(BrowserContent browserField) 
    {
        // Field has full screen.
        return Display.getHeight();
    }

    /**
     * @see net.rim.device.api.browser.field.RenderingApplication#getAvailableWidth(BrowserContent)
     */
    public int getAvailableWidth(BrowserContent browserField) 
    {
        // Field has full screen.
        return Display.getWidth();
    }

    /**
     * @see net.rim.device.api.browser.field.RenderingApplication#getHistoryPosition(BrowserContent)
     */
    public int getHistoryPosition(BrowserContent browserField) 
    {
        // No history support.
        return 0;
    }


    /**
     * @see net.rim.device.api.browser.field.RenderingApplication#getHTTPCookie(String)
     */
    public String getHTTPCookie(String url) 
    {
        // No cookie support.
        return null;
    }

    /**
     * @see net.rim.device.api.browser.field.RenderingApplication#getResource(RequestedResource, BrowserContent)
     */
    public HttpConnection getResource( RequestedResource resource, BrowserContent referrer) 
    {
        if (resource == null) 
        {
            return null;
        }

        // Check if this is cache-only request.
        if (resource.isCacheOnly()) 
        {
            // No cache support.
            return null;
        }

        String url = resource.getUrl();

        if (url == null) 
        {
            return null;
        }

        // If referrer is null we must return the connection.
        if (referrer == null) 
        {
            HttpConnection connection = Utilities.makeConnection(resource.getUrl(), resource.getRequestHeaders(), null);

            return connection;

        } 
        else 
        {
            // If referrer is provided we can set up the connection on a separate thread.
            SecondaryResourceFetchThread.enqueue(resource, referrer);
        }

        return null;
    }

    /**
     * @see net.rim.device.api.browser.field.RenderingApplication#invokeRunnable(Runnable)
     */
    public void invokeRunnable(Runnable runnable) 
    {       
        (new Thread(runnable)).start();
    }
}

/**
 * A Thread class to fetch content using an http connection
 */
final class PrimaryResourceFetchThread extends Thread 
{    
    private BrowserFieldDemo _application;
    private Event _event;
    private byte[] _postData;
    private HttpHeaders _requestHeaders;
    private String _url;

    /**
     * Constructor to create a PrimaryResourceFetchThread which fetches the web
     * resource from the specified url.
     * 
     * @param url The url to fetch the content from
     * @param requestHeaders The http request headers used to fetch the content
     * @param postData Data which is to be posted to the url
     * @param event The event triggering the connection
     * @param application The application requesting the connection
     */
    PrimaryResourceFetchThread(String url, HttpHeaders requestHeaders, byte[] postData, Event event, BrowserFieldDemo application) 
    {
        _url = url;
        _requestHeaders = requestHeaders;
        _postData = postData;
        _application = application;
        _event = event;
    }

    /**
     * Connects to the url associated with this object
     * 
     * @see java.lang.Thread#run()
     */
    public void run() 
    {
        HttpConnection connection = Utilities.makeConnection(_url, _requestHeaders, _postData);
        _application.processConnection(connection, _event);        
    }
}
Was it helpful?

Solution

Here is what I would try:

  1. First, take the URL you are trying to load (it looks like that is http://www.google.com), exit your app, and use the simulator's normal browser app to visit the same URL. Does it work? If it doesn't work in the browser, it won't work in your app, and you need to debug why the simulator can't connect to the network.

  2. Do you have a software firewall (e.g. Windows Firewall) that is blocking the simulator? If you do have a firewall running, you need to make sure that the fledge.exe process is allowed to make network connections, or this won't work. You also might need to grant an exception for the java.exe process. In the case of the BB 7.1 plugin, the fledge process is here for me:

    C:\eclipse\indigo\plugins\net.rim.ejde.componentpack7.1.0_7.1.0.10\components\simulator\fledge.exe

    Of course, the root of that path will be different, depending on where you installed Eclipse.

  3. Try changing the URL, in the Java code. Does the same problem occur with all URLs?

  4. Is http://www.google.com for some reason blocked, where you are? I don't know how internet service providers work everywhere in the world. At the very least, maybe you need to use http://www.google.co.in, or something similar.

  5. I'm not sure which version of BB OS you're trying to target. Most people now (if they're still supporting BlackBerry Java at all) don't support anything lower than OS 5.0. If you can limit your support to OS 5.0+, then I would recommend not even using the code in that demo. In 5.0 there is the BrowserField class, also known as BrowserField2. This class is much easier to use. You can find a separate demo for it in the same BlackBerry samples folder in your plugin. It's called browserfield2demo. Try running that demo, and see if you have the same problems.

  6. If you want to stick with the original (pre 5.0) BrowserFieldDemo, then you might modify the code to get more debugging information. The exception is coming from here:

    catch (RenderingException re) 
    {
        Utilities.errorDialog("RenderingSession#getBrowserContent() threw " + re.toString());
    } 
    

    Try changing the code to

    catch (RenderingException re) 
    {
        Utilities.errorDialog("RenderingSession#getBrowserContent() threw " + re.toString());
        System.out.println(re.printStackTrace());
    } 
    

    and look in the Eclipse Console window for the stack trace. This should give a little more information.

  7. Are you possibly running your simulator with the network connections off? Some people (myself included) are in the habit of starting the simulator with the network connections off, in the hopes that it speeds up the process. Of course, if the app you're testing uses the network, then you'll have to enable it through Options before starting the app. Step (1) above would have failed if the network connections (e.g. GSM or Wi-Fi) were off, but you may not have noticed why it failed.

  8. Is your Eclipse Run/Debug configuration setup to run the app automatically, on simulator startup? If so, I would recommend not doing that, and configure it to have you run the app manually, by clicking the app icon as a user would. You can see if this is setup this way in the Debug Configurations window, Simulator -> General pane. Clear out the box Launch app or URL on startup:

enter image description here

Those are my suggestions. It looks to me like a general network failure. My guess would be a firewall problem (remember that you probably have to add a firewall exception for the simulator in every single JDE plugin version you install ... 5.0, 6.0, 7.0, 7.1).

But try these steps and post more information. Good luck!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top