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: 16
Registered: ‎01-22-2013
My Device: Blackberry9800
My Carrier: JAZZ

Server Not Found Exception

Hello Every one!,

                            I am developing a BB software which interact with Server by recieving XML response from Server..I handle the exception in which server  gives invalid response.. But if my application not able to find Server then what I have to do. I am i want to make an exception in which i could not found server.. Some portion of my code is given below...



public static String getUrl ()
String url = "https://ee.mobi/"; 
return url;

public static String[ ][ ]AgAppXMLParser(String parUrl) {

Document doc;
StreamConnection conn;
String _node,_element;
String[ ][ ] xmlRespone = null;

String url = AgAppHelperMethods.getUrl() + parUrl;

url = AgAppHelperMethods.getNetworkDependentSuffixedURL(url);

if(url == null)
xmlRespone = new String[1][2];
xmlRespone[0][0] = "null";
xmlRespone[0][1] = "No Connection Available!";
return xmlRespone;


//next few lines creates variables to open a
//stream, parse it, collect XML data and
//extract the data which is required.
//In this case they are elements,
//node and the values of an element


DocumentBuilderFactory docBuilderFactory
= DocumentBuilderFactory. newInstance();
DocumentBuilder docBuilder
= docBuilderFactory.newDocumentBuilder();
doc = docBuilder.parse(conn.openInputStream());
doc.getDocumentElement ().normalize ();
NodeList list=doc.getElementsByTagName("*");
_node=new String();
_element = new String();
xmlRespone = new String[list.getLength()][2];

//this "for" loop is used to parse through the
//XML document and extract all elements and their
//value, so they can be displayed on the device


for (int i=0;i<list.getLength();i++)
Node value=list.item(i).
xmlRespone[i][0] = _node;
xmlRespone[i][1] = _element;

}//end for

}//end trying to catch Exceptions but not working
//will catch any exception thrown by the XML parser

catch (IOException ioe)
xmlRespone = new String[1][2];
xmlRespone[0][0] = "null";
xmlRespone[0][1] = ioe.getMessage();
return xmlRespone;
catch (Exception e)
xmlRespone = new String[1][2];
xmlRespone[0][0] = "null";
xmlRespone[0][1] = e.getMessage();
return xmlRespone;

return xmlRespone;




Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Server Not Found Exception

if the server is unreachable you will get an ioexception, which you seem to handle already.
if the file is not found or something else goes wrong your connection should be a httpconnection to be able to handle the response code given by the server.
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter