Genau deshalb hasse ich die Art und Weise, mit der Try-Catch-Blöcke implementiert werden... +seufz+
Fakt ist: irgendwas geht schief.
(Die URL sieht jedenfalls ganz gut aus.)
Problem ist: du weißt nicht was schief geht.
Besser:
public void ReadXML(View v)
{
String URL2 = "http://open.mapquestapi.com/xapi/api/0.6/way[landuse=residential][bbox=9.95194,52.1525,9.95722,52.15556]";
URL website = null;
try
{
website = new URL(URL2);
}
catch(MalformedURLException e)
{
Log.e("ReadXML", "MalformedURL. "+ e.getMessage());
}
if(website == null)
{
Log.e("ReadXML", "Problem: Website == null. Aborting");
return;
}
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = null;
try
{
sp = spf.newSAXParser();
}
catch (ParserConfigurationException e)
{
Log.e("ReadXML", "ParserConfiguration. "+ e.getMessage());
}
catch (SAXException e)
{
Log.e("ReadXML", "SAX - newSAXParser "+ e.getMessage());
}
if(sp == null)
{
Log.e("ReadXML", "Problem: SAXParser == null. Aborting");
return;
}
XMLReader xr = null;
try
{
xr = sp.getXMLReader();
}
catch (SAXException e)
{
Log.e("ReadXML", "SAX - getXMLReader "+ e.getMessage());
}
if(xr == null)
{
Log.e("ReadXML", "Problem: XMLReader == null. Aborting");
return;
}
XMLHandler xmlHandler = new XMLHandler();
xr.setContentHandler(xmlHandler);
InputSource is = null;
try
{
is = new InputSource(website.openStream());
}
catch (IOException e)
{
Log.e("ReadXML", "IO - is "+ e.getMessage());
}
if(is == null)
{
Log.e("ReadXML", "Problem: InputStream == null. Aborting");
return;
}
try
{
xr.parse(is);
}
catch (SAXException e)
{
Log.e("ReadXML", "SAX - parse "+ e.getMessage());
}
catch (IOException e)
{
Log.e("ReadXML", "IO - parse "+ e.getMessage());
}
String information = xmlHandler.getInformation();
Log.e("ReadXML", "Info: "+information);
}
Alles anzeigen
Zitat
02-19 16:04:58.436: ERROR/ReadXML(683): IO - is open.mapquestapi.com
02-19 16:04:58.436: ERROR/ReadXML(683): Problem: InputStream == null. Aborting
IOException beim Versuch, den InputStream zu erzeugen.
Doku sagt:
"Equivalent to openConnection().getInputStream(types)."
Dann versuchen wir das mal.
public void ReadXML(View v)
{
String URL2 = "http://open.mapquestapi.com/xapi/api/0.6/way%5Blanduse=residential%5D%5Bbbox=9.95194,52.1525,9.95722,52.15556%5D";
URL website = null;
try
{
website = new URL(URL2);
}
catch(MalformedURLException e)
{
Log.e("ReadXML", "MalformedURL. "+ e.getMessage());
}
if(website == null)
{
Log.e("ReadXML", "Problem: Website == null. Aborting");
return;
}
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = null;
try
{
sp = spf.newSAXParser();
}
catch (ParserConfigurationException e)
{
Log.e("ReadXML", "ParserConfiguration. "+ e.getMessage());
}
catch (SAXException e)
{
Log.e("ReadXML", "SAX - newSAXParser "+ e.getMessage());
}
if(sp == null)
{
Log.e("ReadXML", "Problem: SAXParser == null. Aborting");
return;
}
XMLReader xr = null;
try
{
xr = sp.getXMLReader();
}
catch (SAXException e)
{
Log.e("ReadXML", "SAX - getXMLReader "+ e.getMessage());
}
if(xr == null)
{
Log.e("ReadXML", "Problem: XMLReader == null. Aborting");
return;
}
XMLHandler xmlHandler = new XMLHandler();
xr.setContentHandler(xmlHandler);
InputSource is = null;
URLConnection connection = null;
try
{
connection = website.openConnection();
}
catch (IOException e)
{
Log.e("ReadXML", "IO - openConnection " + e.getMessage());
}
if(connection == null)
{
Log.e("ReadXML", "Problem: Connection == null. Aborting");
return;
}
InputStream stream = null;
try
{
stream = connection.getInputStream();
}
catch (IOException e)
{
Log.e("ReadXML", "IO - getInputStream " + e.getMessage());
}
if(stream == null)
{
Log.e("ReadXML", "Problem: Stream == null. Aborting");
return;
}
is = new InputSource(stream);
try
{
xr.parse(is);
}
catch (SAXException e)
{
Log.e("ReadXML", "SAX - parse "+ e.getMessage());
}
catch (IOException e)
{
Log.e("ReadXML", "IO - parse "+ e.getMessage());
}
String information = xmlHandler.getInformation();
Log.e("ReadXML", "Info: "+information);
}
Alles anzeigen
(Zum Glück sagt mir meine IDE, welche nicht abgefangenen Exceptions sie so erwartet - da muss ich dann nicht so lange rumsuchen...)
Zitat
02-19 16:14:28.416: ERROR/ReadXML(814): IO - getInputStream open.mapquestapi.com
02-19 16:14:28.416: ERROR/ReadXML(814): Problem: Stream == null. Aborting
Tja, und nun?
Machen wir aus dem e.getMessage() ein e.toString():
Zitat
02-19 16:20:30.796: ERROR/ReadXML(948): IO - getInputStream java.net.UnknownHostException: open.mapquestapi.com
02-19 16:20:30.796: ERROR/ReadXML(948): Problem: Stream == null. Aborting
Aha. Host open.mapquestapi.com unbekannt.
Die Berechtigungen für Internet sind aber gesetzt.
Emulator neu gestartet, nachdem ich mich vergewissert habe, dass das Internet dort korrekt läuft:
Keine Besserung.
open.mapquestapi.com gegen 205.188.201.176 getauscht:
Zitat
02-19 16:29:53.585: ERROR/ReadXML(369): IO - getInputStream java.net.SocketException: Permission denied
02-19 16:29:53.585: ERROR/ReadXML(369): Problem: Stream == null. Aborting
Och mennoooo, falsche AndroidManifest.xml angepasst... +knurr+
Zitat
02-19 16:33:04.236: ERROR/ReadXML(433): Info: residential
Aha.
Dann wieder zurück von IP auf Hostnamen:
Zitat
02-19 16:33:52.825: ERROR/ReadXML(466): Info: residential
Jau, läuft.
(Das war dann mal ein Crash-Kurs im Debugging. Wobei 'crash' in Verbindung mit '30 Minuten' echt geprahlt ist... :P)