0
샘플 Android 앱에서 weather API의 URL을 구문 분석하려고하지만 url을 구문 분석하는 동안 예외가 발생합니다.android 응용 프로그램에서 url 구문 분석하는 방법
내가 try 블록의 마지막 문장을 언급하는 경우 :
xr.parse(new InputSource(url.openStream()));
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");
}
다음은 예외가 발생할 경우 log cat의 스크린 샷입니다.
new InputSource(url.openStream());
뭔가를 반환
xr.parse(new InputSource(url.openStream()));
에서 :
MainActivity.java의 95 행은 무엇입니까? –
나는 xr.parse를 가정한다 (새로운 InputSource (url.openStream())); xr이 null 인 행 95입니다. 해당 줄에 주석을 달면 예외가 발생하지 않으므로. –
xr.parse (새 InputSource (url.openStream())); 95 행 – user1703737