-1

これは、サーバーから xml 応答を取得する以下のコードです。このコードで要求タイムアウト タイマーを設定するにはどうすればよいですか?? サーバーが応答しない場合、アプリケーションが例外を返す

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



    String _node,_element;
    String[][] xmlRespone = null;
    try {

            String url = www.xyz.com;
            URL finalUrl = new URL(url);    


            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            Document doc = db.parse(new InputSource(finalUrl.openStream()));
            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();
                    _element=value.getNodeValue();
                    xmlRespone[i][0] = _node;
                    xmlRespone[i][1] = _element;

                }//end for

        }//end try











    catch (Exception e)
    {
      flag=false;
      Log.e(LOG_TAG, "CONNECTION ERROR   SERVER NOT RESPONDING", e);
    } 



    return xmlRespone;         

}
4

1 に答える 1

0

このためには、タイマーを実装する必要があります...以下の参照リンクを参照してください...

Androidでタイマーを設定する方法

Android: タイマーの使い方

Android のタイマー

これがあなたを助けることを願っています...

于 2012-09-19T11:04:34.107 に答える