java - NullPointerException when parsing XML data with geocoding API in Processing -


i using processing , loading data csv table, 1 column includes country names. each country trying use google geocoding api respective latitude , longitude values, getting nullpointerexception error. here code:

import processing.xml.*;  bubble[] bubbles; table table;  void setup() {   size(displaywidth, displayheight);   loaddata(); }    void draw() {   background(255);   (int = 0; < bubbles.length ; i++) {     bubbles[i].display();     bubbles[i].rollover(mousex, mousey);        } }  void loaddata() {  table = loadtable("terroristattacks.csv", "header");   bubbles = new bubble[table.getrowcount()];    (int = 0; < table.getrowcount(); i++) {    tablerow row = table.getrow(i);    float estimate = row.getfloat("estimate");    float diameter = estimate*0.17;    string name = row.getstring("name");    string country = row.getstring("country");    int year = row.getint("date");     api_key = "my_api";    string location = country;    string url =    "https://maps.googleapis.com/maps/api/geocode/xml?address=" +   location + "&key=" + api_key;    xml root = loadxml(url);    xml lat = root.getchild("result/geometry/location/lat");    xml lng = root.getchild("result/geometry/location/lng");     float latitude = lat.getfloatcontent();        float longitude = lng.getfloatcontent();     float x = random(diameter/2, width-diameter/2);     float y = random(diameter/2, height-diameter/2);     println();    println(estimate + " estimate: row " + + " name " + name +     ". x = " + x + ", y = " + y + ", diameter = " + diameter + ", date: " +    year + ", country: " + location);    println(url);             bubbles[i] = new bubble(x, y, diameter, name, year);  }  }  boolean sketchfullscreen() { // full screen   return true;  } 

and error appears @ line:

float latitude = lat.getfloatcontent();  

fyi, when commenting above line , 1 after (float longitude) don't error message , receive every url (for each country) printed in console.

could help? thanks, ilias

here xml response pakistan:

<geocoderesponse>  <status>ok</status>  <result>   <type>country</type>   <type>political</type>   <formatted_address>pakistan</formatted_address>   <address_component>    <long_name>pakistan</long_name>    <short_name>pk</short_name>    <type>country</type>    <type>political</type>   </address_component>   <geometry>    <location>     <lat>30.3753210</lat>     <lng>69.3451160</lng>    </location>    <location_type>approximate</location_type>    <viewport>     <southwest>      <lat>23.6946945</lat>      <lng>60.8729720</lng>     </southwest>     <northeast>      <lat>37.0841070</lat>      <lng>77.8316195</lng>     </northeast>    </viewport>    <bounds>     <southwest>      <lat>23.6946945</lat>      <lng>60.8729720</lng>     </southwest>     <northeast>      <lat>37.0841070</lat>      <lng>77.8316195</lng>     </northeast>    </bounds>   </geometry>   <place_id>chijh3x9-njs2zgrxjiu5veht0y</place_id>  </result> </geocoderesponse> 


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -