how to add request time out exception
<p>how do i add request time out in  my code? </p>

<p>below is my code which call http class  for acess server and get response but i want to add timeout exception  </p>

<p>*<em>so if within 15 second server not response timeout request called what do i do? *</em></p>

<pre><code>  public class AgAppTransAirTimeTopUp  extends Activity
  {
      private String[][] xmlResponse;

    public void onCreate(Bundle savedInstanceState)
  {

                xmlResponse =  
 AgAppHelperMethods.AgAppXMLParser("AG_IT_App/AgMainServlet?source  
 ="+AgAppHelperMethods.varM      obileNo+"&amp;mobile="+AgAppHelperMethods.varMobileNo+"&amp; 
 pin="+AgAppHelperMethods.getPIN(txtTATpinno.getText().toString())+"&amp;messageType=ATO&amp; 
 channel=INTERNET);
                 if(!AgAppHelperMethods.flag)
                    {

 Toast.makeText(getApplicationContext(), "Invalid Input " , Toast.LENGTH_SHORT).show();
                //       AirTimeProgressDialog.dismiss();
                    }
                    else
                    {

                 Intent j = new Intent(AgAppTransAirTimeTopUp.this,  
        AgAppTransATTPResponse.class);                   
                 MyBean bean = new MyBean();
                 bean.set2DArray(xmlResponse);
                 Bundle b = new Bundle();
                 b.putSerializable("mybean", bean);
                 j.putExtra("obj", b);
                 startActivity(j);
        //            value=false;
                    }        //       
       AirTimeProgressDialog.dismiss();

        }

        }

        catch  (Exception e)
        {
    Toast.makeText(AgAppTransAirTimeTopUp.this, "Invalid Input " ,   
         Toast.LENGTH_SHORT).show();                  
        }



            public class AgAppHelperMethods 
         {

   private static final String LOG_TAG = null;
   private static AgAppHelperMethods instance = null;
   static boolean flag=null != null;




                 public static String smsResponse[][] = new String[20][2];

     String[][] xmlRespone = null;     
   public static AgAppHelperMethods getInstance() 
   {
      if(instance == null) 
          {
             instance = new AgAppHelperMethods();
          }
      return instance;
   }

    public static String getUrl () 
      { 
        String url = "https://xyzaaaaaa/";            
        return url;      
      }

  public static   String[][] AgAppXMLParser( String parUrl) 
  {     
    flag = true;       
    String _node,_element;
    String[][] xmlRespone = null;
    HttpURLConnection urlConnection = null;       
    try 
        {
                String url = AgAppHelperMethods.getUrl() + parUrl;
                URL finalUrl = new URL(url);                
                urlConnection = (HttpURLConnection)  
                       finalUrl.openConnection();
                urlConnection.setConnectTimeout(3000);                
                urlConnection.connect();                
                DocumentBuilderFactory dbf =  
                   DocumentBuilderFactory.newInstance();
                DocumentBuilder db = dbf.newDocumentBuilder();
                Document doc = db.parse(finalUrl.toString());

                       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&lt;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                  
                urlConnection.disconnect();      
        }//end try  
         catch (Exception e)
           {
             flag=false;
             Log.e(LOG_TAG, " Host not responding", e);
             Messages.setMessage("error"+e.getMessage());
         }  
     return xmlRespone;        

  } 
</code></pre>
