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: 157
Registered: ‎02-18-2009
My Device: Not Specified
Accepted Solution

“Base URI must be non-null” NP exception thrown when creating BrowserContent

“Base URI must be non-null” exception creating a BrowserContent

 

I use BrowserContent to display HTML in a field. Because I need to support at least OS 4.5 I had to create my own HttpConnection and RenderingApplication implementation to handle the loading of HTML. This all works fine on <= OS 4.7 (have tested it on Bold, Storm, Pearl, 8700) but not on OS 5 (not on the simulator and on a real device). I always get a NullPointerException “Base URI must be non-null”.

 

The debugger shows me that the exception is thrown by URI.resolveAgainst which is called from the constructor of URI. The exception seems always to be thrown when resolving the relative URL for the favicon (/favicon.ico). Note that my application does not specify any favicon so it seems that the browser tries to download one (which is default behavior with most browsers).

 

The code to add the Browser as a field is as follows:

 

 

 

HttpConnection connection = new StaticHTTPConnection(data, charset, 
MimeContentType.HTML_CONTENT_TYPE);

RenderingSession renderingSession = RenderingSession.getNewInstance();

BrowserContent browserContent = renderingSession.getBrowserContent(connection,
getRenderingApplication(), 0);

 

The exception is thrown when executing renderingSession.getBrowserContent.

 

 

The overloaded getBrowserContent methods of RenderingSession with a HttpConnection parameter do not support the baseURL parameter. I however tried to use the other methods that support the baseURL parameter (parameter is called url) but that didn't solve it (same exception).

 

Any idea how to solve this?

 

Kind regards,

 

Martijn Brinkers

Developer
Posts: 157
Registered: ‎02-18-2009
My Device: Not Specified

Re: “Base URI must be non-null” NP exception thrown when creating BrowserContent

As a workaround I can force the content-location to be used as the base URL. This seems to solve the NPE. The constant 

USE_CONTENT_LOCATION_AS_BASE_URI is however a hidden constant.

 

 

final int USE_CONTENT_LOCATION_AS_BASE_URI = 49;
        
BrowserContent browserContent = renderingSession.getBrowserContent(connection,
getRenderingApplication(), USE_CONTENT_LOCATION_AS_BASE_URI);

 

Any other suggestions need requiring undocumented features?

 

Kind regards,

 

Martijn Brinkers

 

New Developer
Posts: 3
Registered: ‎01-15-2010
My Device: 8800
My Carrier: AT&T

Re: “Base URI must be non-null” NP exception thrown when creating BrowserContent

I've been looking for a solution to this all week.  Martijn, you saved me from the crazy house!

 

How did you come across USE_CONTENT_LOCATION_AS_BASE_URI?

 

- Harry

Developer
Posts: 157
Registered: ‎02-18-2009
My Device: Not Specified

Re: “Base URI must be non-null” NP exception thrown when creating BrowserContent

The contents of .class file contains constants that are private. I often 'look'  at the contents of the .class (using a decompiler) because it's sometimes faster than looking up the Javadoc.

Developer
Posts: 157
Registered: ‎02-18-2009
My Device: Not Specified

Re: “Base URI must be non-null” NP exception thrown when creating BrowserContent

The probem with the USE_CONTENT_LOCATION_AS_BASE_URI workaround is that this does not work on < OS 5 (and probably also not on old releases of OS 5). When I use USE_CONTENT_LOCATION_AS_BASE_URI with <= OS 4.7 the browser seems to wait on something indefinitely.

 

So, I add the workaround based on OS version.

 

Is this a bug?

Developer
Posts: 157
Registered: ‎02-18-2009
My Device: Not Specified

Re: “Base URI must be non-null” NP exception thrown when creating BrowserContent

Anyone?
New Developer
Posts: 17
Registered: ‎12-02-2009
My Device: Not Specified

Re: “Base URI must be non-null” NP exception thrown when creating BrowserContent

Hi Martijn,

 

I tried your solution. It indeed renders HTML content, even on Storm2(9550) 5.0.0.334. However, text does not wrap withing the container.

 

Have you faced this issue? can you suggest any workaround?

 

- Thanks bbdeveloper2009

Developer
Posts: 157
Registered: ‎02-18-2009
My Device: Not Specified

Re: “Base URI must be non-null” NP exception thrown when creating BrowserContent

"However, text does not wrap withing the container."

 

No I don't have this problem. I have however not tested it on a Storm 2, only on Storm 1 upgraded to OS 5.

New Developer
Posts: 17
Registered: ‎12-02-2009
My Device: Not Specified

Re: “Base URI must be non-null” NP exception thrown when creating BrowserContent

It works great on Storm1, however text fails to wrap on Storm2

 

I have not been able to find any workaround for this issue Smiley Sad

Contributor
Posts: 10
Registered: ‎03-10-2010
My Device: 9550
My Carrier: Vodaphone

Re: “Base URI must be non-null” NP exception thrown when creating BrowserContent

I have the same problem with you.

In my case, my application runs perfectly on OS 4.7. But when it runs on OS 5.0, I have the same message as you have.

 

My work around is :

In your StaticHttpConnection,

 

you should implement: getURL(), getHost() to return "http://www.google.com". and "www.google.com"

Smiley Very Happy

 

It's a dirty trick but it works.

 

Ball