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: 13
Registered: ‎10-20-2010
My Device: Not Specified

help!! Loss network connection and wifi ...(XML file)

I need read XML file from internet, but when read the file, closes the aplication , i need some help that is wrong..

In the emulator the code works perfectly, the problem is when I put it on the phone


XML is my hosting

the code goes something like running the method ConXML trying to connect to the wifi network, if an error occurred trying to connect to the network the phone, if no error reads all the elements "item" of XML and stores under the names in a String [- ] for later viewing as buttons. in the simulator all perfect, but sometimes the phone connects but almost always loses the connection, or never there, also if you connect it is looking and completely close the application an error occurs;

My questions:
-There is a problem in the code of connection, if that's not the way to connect to both networks.

And how to do that if it fails to connect after a timeout or cancel closing method and not close the application.





                  int res=ConXML("http://Example/Lecturas.xml;deviceside=true"+wifi,"");
                  wifi=" ";
                  int res2=ConXML("http://Example/Lecturas.xml;deviceside=true","");
                         Dialog.alert("Error de Conexión");


public int ConXML(String url,String id_mes)
            NodeList list= null;
                DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory. newInstance();
                DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
                Document doc = docBuilder.parse(con.openInputStream());
                doc.getDocumentElement ().normalize ();   
                list=doc.getElementsByTagName("item");//captura todos los nodos item
            catch (Exception e)


                    return pwifi;
                _node = new String();
                int x=0;
                for (int i=0;i<list.getLength();i++){//este ciclo recorre todos los nodos del XMl                

                     _Nombre_desc[x]=_node;//Coloca el nombre
                }//end for             
                 return 0;
        } //Fin public ConXML

Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: help!! Loss network connection and wifi ...(XML file)

I would strongly recommend re-writing this process to separate the obtaining of the data and the processing of the data.  So connect to the Server, get the data, close the connection, and if you connect OK and get data, then try to parse the data.


Make this change, and then confirm that the problem is in the connection and not the processing.


I would also implement some better debugging/tracing with this code so that when problems occur you can figure out where the problem was.


Also can you confirm that you have compiled suing an appropriate level of the OS for the phones you are attempting to run this on.