<image>
태그에서 이미지 URL을 구문 분석하기위한 코드를 작성했습니다. 이미지 태그에서 이미지 URL을 파싱하는 문제
코드
은 다음과 같습니다 :NodeList imageLink = docElement.getElementsByTagName("image");
String nUrl;
if (imageLink.toString() != null) {
Element element = (Element) imageLink.item(0);
NodeList imageUrl = element.getElementsByTagName("url");
if (imageUrl.toString() != null) {
Element imageFirst = (Element) imageUrl.item(0);
nUrl = imageFirst.getFirstChild().getNodeValue();
Log.d(TAG,
"<<<<<<<<<<<<<<<<<<<<<<..............Image Url is : "
+ nUrl
+ ".....................>>>>>>>>>>>>>>>>>.....");
} else {
Log.d(TAG,
"<<<<<<<<<<<<<<<<<<<<<<..............Image Url is null : .....................>>>>>>>>>>>>>>>>>.....");
nUrl = "http://static.dnaindia.com/images/710/logo_dna_rss.gif";
}
} else {
Log.d(TAG,
"<<<<<<<<<<<<<<<<<<<<<<..............Image tag is not found.....................>>>>>>>>>>>>>>>>>.....");
nUrl = "http://static.dnaindia.com/images/710/logo_dna_rss.gif";
}
IT는 rss feed which having <image> tag
와 함께 잘 작동했다. <image>
URL이없는 Rss의 기본 이미지를 설정하고 싶습니다.
내 코드는 NodeList imageUrl = element.getElementsByTagName("url");
에 java.lang.NullPointerException
으로 표시됩니다.
NodeList
에 대해 null을 확인하는 방법은 무엇입니까?
그리고 그것을 수정하는 아이디어.
미리 감사드립니다.
그것은 널 (null) 인'element' 객체입니다. 'if (null! = element)'가 할 것입니다. – 1615903