B
birdman
Neues Mitglied
- 0
Hallo,
folgender Code funktioniert bei einer normalen Java - Application problemlos:
Aus irgendeinem Grund ist connection.getInputStream() in meiner Android Appimmer leer ich bekomme einfach die XML nicht geparst und finde nicht raus warum. (Der Code funktionier einwandfrei wenn ich ihn in einer normalen Java Application teste)
<uses-permission android:name="android.permission.INTERNET" > ist gesetzt.
Hoffe mir kann jemand helfen,
danke!
gruß
folgender Code funktioniert bei einer normalen Java - Application problemlos:
Code:
private String start(String start, String end) throws Exception
{
start = URLEncoder.encode(start, "UTF-8");
end = URLEncoder.encode(end, "UTF-8");
URL url = new URL("http://maps.googleapis.com/maps/api/directions/xml?origin="+start+"&destination="+end+"&sensor=false");
URLConnection connection = url.openConnection();
[B]Document doc = parseXML(connection.getInputStream());[/B] //Problemzone: [B]connection.getInputStream() [/B]ist immer leer.
NodeList polyline = doc.getElementsByTagName("overview_polyline"); // polyline zum decodieren auslesen
return polyline.item(0).getTextContent();
}
private Document parseXML(InputStream stream)
throws Exception
{
DocumentBuilderFactory objDocumentBuilderFactory = null;
DocumentBuilder objDocumentBuilder = null;
Document doc = null;
try
{
objDocumentBuilderFactory = DocumentBuilderFactory.newInstance();
objDocumentBuilder = objDocumentBuilderFactory.newDocumentBuilder();
doc = objDocumentBuilder.parse(stream);
}
catch(Exception ex)
{
throw ex;
}
return doc;
}
}
<uses-permission android:name="android.permission.INTERNET" > ist gesetzt.
Hoffe mir kann jemand helfen,
danke!
gruß