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

Posts: 62
Registered: ‎05-29-2009
My Device: Not Specified

Re: MIDP and DNSException

This is obviously an old thread but we're seeing this too.  It is almost like the DNS lookup failure is being cached.  Is there a bugfix or a workaround other than manually clearing/updating the cache?

New Developer
Posts: 3
Registered: ‎08-30-2009
My Device: Bold 9000 and Curve 8310

Re: MIDP and DNSException

[ Edited ]

Although this is a very old forum, I stumbled across it because I was also getting a large number of DNSExceptions and couldn't figure out why. After doing some research and using Sohm's advice, I looked at the HTTPDemo bundled with the JDE.


The one thing I did note was that the main difference between your code and the HTTPDemo is the use of Connection vs. StreamConnection. In my own code, I was using HttpConnection conn =(HttpConnection)Connector.open(url), but I would intermittently get DNSExceptions; there was no rhyme or reason to why.


Since then, I have implemented something similar to the following snippet and no longer receive DNSExceptions.  Of course, I wrap all of this in a try-catch.


StreamConnection s = null;
sc = (StreamConnection)Connector.open(_url);
HttpConnection httpConn = (HttpConnection)sc;

int status = httpConn.getResponseCode();

if (status == HttpConnection.HTTP_OK) {
    InputStream input = sc.openInputStream();

    //... Do something with the stream ... 

} else {    
    //Process an HTTP Failure scenario


Hope this helps anyone else having these problems. It was frustrating to me to say the least.