title: Android: Exception: Connection timeout
body: <p>I keep getting this problem
   Exception: Connection timeout
  I am running my project on another device so i have to use the IP adress. So i change <code>localhost:8080/lab/lab1.xml</code> to <code>http://192.168.1.5/lab/lab1.xml</code>
  Now after i run and it load for a while on the device after loading it then displays a
  blank page. and when i checked Logcat it displays Exception: Connection timeout
  Help me please. Thanks</p>
  
  <p>So here is the MainActivity.java</p>
  
  <pre><code>import android.app.Activity;
  import android.app.ProgressDialog;
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.widget.TextView;
  
  public class MainActivity extends Activity {
  
      TextView tvResponse;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          tvResponse = (TextView) findViewById(R.id.tvResponse);
          new PostAsync().execute();
      }
  
      class PostAsync extends AsyncTask&lt;Void, Void, Void&gt; {
          ProgressDialog pd;
          XMLHelper helper;
  
  
          @Override
          protected void onPreExecute() {
              pd = ProgressDialog.show(MainActivity.this, "by Es", "Loading", true, false);
          }
          @Override
          protected Void doInBackground(Void... arg0) {
              helper = new XMLHelper();
              helper.get();
              return null;
          }
  
  
          @Override
          protected void onPostExecute(Void result) {
              StringBuilder builder = new StringBuilder();
              for(EventValue event : helper.events) {
                  builder.append("\nWhat: " + event.getWhat());
                  builder.append("\nWhen: " + event.getWhen());
                  builder.append("\nWhere: " + event.getWhere());
                  builder.append("\n");
              }
              tvResponse.setText(builder.toString());
              pd.dismiss();
          }
  
      }
  
  }
  </code></pre>
  
  <p>Here is the XMLHelper.java</p>
  
  <pre><code>import java.io.InputStream;
  import java.net.URL;
  import java.util.ArrayList;
  
  import javax.xml.parsers.SAXParser;
  import javax.xml.parsers.SAXParserFactory;
  
  import org.xml.sax.Attributes;
  import org.xml.sax.InputSource;
  import org.xml.sax.SAXException;
  import org.xml.sax.XMLReader;
  import org.xml.sax.helpers.DefaultHandler;
  
  import android.util.Log;
  
  public class XMLHelper extends DefaultHandler {
      /** 
       * The URL to be parsed
       */
      private String URL_MAIN = "http://192.168.1.5/lab/lab1.xml";
      String TAG = "XMLHelper";
  
      Boolean currTag = false;
      String currTagVal = "";
      public EventValue event = null;
      public ArrayList&lt;EventValue&gt; events = new ArrayList&lt;EventValue&gt;();
  
  
      public void get() {
          try {
              SAXParserFactory factory = SAXParserFactory.newInstance();
              SAXParser mSaxParser = factory.newSAXParser();
              XMLReader mXmlReader = mSaxParser.getXMLReader();
              mXmlReader.setContentHandler(this);
              InputStream mInputStream = new URL(URL_MAIN).openStream();
              mXmlReader.parse(new InputSource(mInputStream));
          } catch(Exception e) {
              // Exceptions can be handled for different types
              // But, this is about XML Parsing not about Exception Handling
              Log.e(TAG, "Exception: " + e.getMessage());
          }
      }
  
  
      @Override
      public void characters(char[] ch, int start, int length)
              throws SAXException {
          if(currTag) {
              currTagVal = currTagVal + new String(ch, start, length);
              currTag = false;
          }
      }
  
  
      @Override
      public void endElement(String uri, String localName, String qName)
              throws SAXException {
          currTag = false;
  
          if(localName.equalsIgnoreCase("what"))
              event.setWhat(currTagVal);
  
          else if(localName.equalsIgnoreCase("when"))
              event.setWhen(currTagVal);
  
          else if(localName.equalsIgnoreCase("where"))
              event.setWhere(currTagVal);
  
          else if(localName.equalsIgnoreCase("event"))
              events.add(event);
      }
  
  
      @Override
      public void startElement(String uri, String localName, String qName,
              Attributes attributes) throws SAXException {
          Log.i(TAG, "TAG: " + localName);
  
          currTag = true;
          currTagVal = "";
  
          if(localName.equals("event"))
              event = new EventValue();
      }
  }
  </code></pre>
  
  <p>Here is the EventValue.java</p>
  
  <pre><code>public class EventValue {
      String what, when, where;
  
      public String getWhat() {
          return what;
      }
  
      public void setWhat(String what) {
          this.what = what;
      }
  
      public String getWhen() {
          return when;
      }
  
      public void setWhen(String when) {
          this.when = when;
      }
  
      public String getWhere() {
          return where;
      }
  
      public void setWhere(String where) {
          this.where = where;
      }
  
  
  
  }
  </code></pre>
  
  <p>Here is the xml file lab1.xml (localhost:8080/lab/lab1.xml)</p>
  
  <p>
  </p>
  
  <pre><code> &lt;event&gt;
      &lt;what&gt;Summer&lt;/what&gt;
      &lt;when&gt;March1&lt;/when&gt;
      &lt;where&gt;--&lt;/where&gt;
  &lt;/event&gt;
  
   &lt;event&gt;
      &lt;what&gt;asdasdas&lt;/what&gt;
      &lt;when&gt;March 2&lt;/when&gt;
      &lt;where&gt;asasas&lt;/where&gt;
  &lt;/event&gt;
  
   &lt;event&gt;
      &lt;what&gt;asdasdq&lt;/what&gt;
      &lt;when&gt;asdasdx&lt;/when&gt;
      &lt;where&gt;asdasdf&lt;/where&gt;
  &lt;/event&gt;
  </code></pre>
  
  <p></p>