If you are using Internet Explorer, please remove blackberry.com from your compatibility view settings.

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
Contributor
khalidhabib
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;
try{

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;
}

conn=(StreamConnection)Connector.open(url);

//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();
docBuilder.isValidating();
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).
getChildNodes().item(0);
_node=list.item(i).getNodeName();
if(value==null)
{_element=null;}
else
{_element=value.getNodeValue();}
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;

}

 

 

Please use plain text.
Developer
simon_hain
Posts: 15,893
Registered: ‎07-29-2008
My Device: Z10 LE
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
Please use plain text.