Array of XMLElements NPE error
in
Programming Questions
•
2 years ago
Hi, I'm trying to take locations from a New york times XML document and use them to find latitude and longitude points using a yahoo placefinder api. I extracted the locations from articles and then fed them into an array of strings, each one a URI link to a different placefinder XML doc and then I tried to create an an array of XMLElements from the array of URI's (news[j].joinedAPI refers to the array of URI links):
XMLElement[] location;
location= new XMLElement[totalItems];
for (int j = 0; j < news.length; j ++ ) {
location[j] = new XMLElement(this, news[j].joinedAPI );
XMLElement coordinates = location[j].getChild(5);
XMLElement elementLatitude = coordinates.getChild(1);
int latitude = int(elementLatitude.getContent());
XMLElement elementLongitude = coordinates.getChild(2);
int longitude = int(elementLongitude.getContent());
news[j].display();
}
But I'm getting a nullPointerException on this line: location[j] = new XMLElement(this, news[j].joinedAPI );
What am i doing wrong?
XMLElement[] location;
location= new XMLElement[totalItems];
for (int j = 0; j < news.length; j ++ ) {
location[j] = new XMLElement(this, news[j].joinedAPI );
XMLElement coordinates = location[j].getChild(5);
XMLElement elementLatitude = coordinates.getChild(1);
int latitude = int(elementLatitude.getContent());
XMLElement elementLongitude = coordinates.getChild(2);
int longitude = int(elementLongitude.getContent());
news[j].display();
}
But I'm getting a nullPointerException on this line: location[j] = new XMLElement(this, news[j].joinedAPI );
What am i doing wrong?
1