01-15-2010 07:05 AM
“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,
RenderingSession renderingSession = RenderingSession.getNewInstance();
BrowserContent browserContent = renderingSession.getBrowserContent(connection,
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?
Solved! Go to Solution.
01-15-2010 09:40 AM
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,
Any other suggestions need requiring undocumented features?
01-15-2010 03:39 PM
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?
01-15-2010 04:36 PM
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.
01-15-2010 05:20 PM
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?
03-05-2010 09:24 AM
I tried your solution. It indeed renders HTML content, even on Storm2(9550) 22.214.171.1244. However, text does not wrap withing the container.
Have you faced this issue? can you suggest any workaround?
- Thanks bbdeveloper2009
03-05-2010 09:35 AM
"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.
03-23-2010 12:03 PM
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,
It's a dirty trick but it works.