I want to parse the URL of a weather API in my sample Android app, but it arises an exception while parsing the url.
If I comment the last statement of the try block:
xr.parse(new InputSource(url.openStream()));
then my program runs successfully. Please revise my code where I parse my URL.
try {
URL url;
String queryString ="http://free.worldweatheronline.com/feed/weather.ashx?q=34.01,71.54&format=xml&num_of_days=5&key=ccad66928f081759132201";
url = new URL(queryString.replace(" ", "%20"));
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
WeatherHandler myWeatherHandler = new WeatherHandler();
xr.setContentHandler(myWeatherHandler);
xr.parse(new InputSource(url.openStream()));
Log.d(TAG, "it's all right");
} catch (Exception e) {
System.out.println(e);
Log.d(TAG, "it's Wrong");
}
Here is the Screen shot of the log cat when the exception occurs.

Are you sure the line:
from
is returning something? If you have to connect to the Internet, don’t forget to add the permissions to the manifest. And you should also test if you actually get something from that url before trying to parse.
At least that’s my interpretation from your Log and Exception.