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
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.

 

 

 

pwifi=o;

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

 

public int ConXML(String url,String id_mes)
        {
            NodeList list= null;
 
            try
            {
                //ConXML("http://Example/Lecturas.xml;deviceside=true"+wifi,"");
                  
                con=(StreamConnection)Connector.open(url);
                DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory. newInstance();
                DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
                docBuilder.isValidating();
                Document doc = docBuilder.parse(con.openInputStream());
                doc.getDocumentElement ().normalize ();   
                list=doc.getElementsByTagName("item");//captura todos los nodos item
      
               con.close();
            }
            catch (Exception e)
            {      

                    pwifi=pwifi+1;

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

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

Developer
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.