如何在此代码中设置请求超时?这是我的应用程序,如果 http 服务器没有响应或不可用的应用程序爆炸,它工作正常我如何在这个应用程序中设置请求超时?请帮我
public class AgAppHelperMethods {
private static final String LOG_TAG = null;
private static AgAppHelperMethods instance = null;
public static String[][] AgAppXMLParser( String parUrl) {
String _node,_element;
String[][] xmlRespone = null;
try {
String url = "www.xxxx.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;
}
}
catch (Exception e)
{
Log.e(LOG_TAG, "Connection Error NET NOT WORKING", e);
}