How to stop application for blast if no network is available?
<p>I have a class, which does not extend activity, that shows an error if no Internet connection is available</p>

<p>If Internet is available it works fine, but when Internet is not available or if the server is busy, then the application force closes. How do I prevent this? How can I print catch block message in main activity class?</p>

<p>How to  stop application from crashing if there is no network is available?</p>

<pre><code>   public class AgAppHelperMethods   {


  private static final String LOG_TAG = 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];


            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

        }//end try









 catch (Exception e)
 {
     Log.e(LOG_TAG, "Connection Error NET NOT WORKING", e);
     }





    return xmlRespone;         

}



        public class LoginScreen extends Activity implements Serializable {


public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    setContentView(R.layout.agapplogin);
          btnLogin = (Button) findViewById(R.id.btnLogin);

            btnLogin.setOnClickListener(new OnClickListener() {

                            public  void  
          onClick(View     view) {
            postLoginData();

             public void postLoginData()

{
             xmlRespone = AgAppHelperMethods.AgAppXMLParser( "www.xxx.com);


        Intent i = new Intent(this.getApplicationContext(),   
      Activity2.class);
        Bundle bundle = new Bundle();
        bundle.putSerializable("xmlResponee", xmlRespone.toString());
        i.putExtras(bundle);
        //i.putExtra("OBJECT", xmlRespone)
</code></pre>
