Getting a null value when attempting to get KML node value from phone, but not on the emulator with android
<p>I am currently designing an application that needs to plot a route on a MapView. For this to function correctly I need to get data from a KML document that i get from:</p>

<p><a href="http://maps.google.com/maps?f=d&amp;hl=en&amp;saddr=-33.882993,18.63486&amp;daddr=-33.870162,18.657837&amp;ie=UTF8&amp;0&amp;om=0&amp;output=kml" rel="nofollow">http://maps.google.com/maps?f=d&amp;hl=en&amp;saddr=-33.882993,18.63486&amp;daddr=-33.870162,18.657837&amp;ie=UTF8&amp;0&amp;om=0&amp;output=kml</a></p>

<p>I have created a test project to ensure that this data is received correctly. The problem is that it runs perfectly on my emulator, but not on the actual android phone.</p>

<p>The following piece of code starts a thread when a button is clicked, getting an input stream response (KML).</p>

<pre><code>public void onClick(View v) {
        if (v.getId()== R.id.btn1)
        {   
              new Thread() {
                 @Override
                 public void run() {
                    String url = "http://maps.google.com/maps?f=d&amp;hl=en&amp;saddr=-33.882993,18.63486&amp;daddr=-33.870162,18.657837&amp;ie=UTF8&amp;0&amp;om=0&amp;output=kml";
                    InputStream is = getConnection(url);

                    mRoad = RouteProvider.getRoute(is);
                    mHandler.sendEmptyMessage(0);
                 }
             }.start(); 
        }   

}

private InputStream getConnection(String url) {
    InputStream is = null;
    try {
           HttpURLConnection conn = (HttpURLConnection)new URL(url).openConnection();
            conn.connect();
            is = conn.getInputStream();
            conn = null;
    } catch (MalformedURLException e) {
            e.printStackTrace();
    } catch (IOException e) {
            e.printStackTrace();
    }
     return is;
    }
</code></pre>

<p>For the moment, all getRoute() needs to do is give the contents of the "LineString" element inside the KML Document. These contents are a list of coordinates that can be used to draw a route.</p>

<pre><code>public class RouteProvider {
    /** Gets data from KML response **/
    public static Road getRoute(InputStream is) {
        Road road = new Road();

        try 
        {
            Document xmlDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is);
            NodeList a = xmlDoc.getElementsByTagName("LineString");
            System.out.println(a.item(0).getTextContent());
            road.mName = a.item(0).getTextContent();


        } catch (SAXException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        }   


        return road;
      }
</code></pre>

<p>On the emulator I am running the correct value is displayed within road.mName, which is a list of coordinates. On a Android phone it displays null?</p>

<p>I am building for Android 2.3.3 on eclipse and I used a Samsung Galaxy S2 for testing.</p>
