java - Foursquare Api for venue search not working -
i new foursquare api. trying learn doing simple program print venues in given latitude , longitude. getting null pointer exception.
import fi.foyt.foursquare.api.foursquareapi; import fi.foyt.foursquare.api.foursquareapiexception; import fi.foyt.foursquare.api.result; import fi.foyt.foursquare.api.entities.compactvenue; import fi.foyt.foursquare.api.entities.venuessearchresult; public class sample { public venues venueslist = new venues(); public static void main(string[] args) { // todo auto-generated method stub try { foursquareapi foursquareapi = new foursquareapi("f3bnuxlwufgtwkstwxq4mntyvf4csrmtdvqxzkfqub1xwbt0", "kkuwa3wsqozj2k1mpbbik3eqolota3kzjhvfppfzpr0vih4e", "http://www.eatin.com/redirect_uri"); string latitude = "+40.689060"; string longitude = "-74.044636"; searchvenues(latitude+","+longitude,foursquareapi ); } catch (foursquareapiexception e) { // todo auto-generated catch block e.printstacktrace(); } } public static void searchvenues(string ll,foursquareapi foursquareapi1) throws foursquareapiexception { result<venuessearchresult> result = foursquareapi1.venuessearch(ll, null, null, null, null, null, null, null, null, null, null); if (result != null){ system.out.println("not null"); system.out.println(result.getresult()); venues venues = new venues(); (compactvenue venue : result.getresult().getvenues()) { venues.add(venue); } system.out.println("---------------start list------------"); (compactvenue venue : venues.getvenues()) { fi.foyt.foursquare.api.entities.location loc = venue.getlocation(); double lang = loc.getlat(); double lng = loc.getlng(); system.out.println("name: "+venue.getname()); system.out.println("distance: "+venue.getlocation().getdistance()); } } } }
venues. java
import java.util.collections; import java.util.linkedlist; import java.util.list; import fi.foyt.foursquare.api.entities.compactvenue; public class venues { private list<compactvenue> venues = new linkedlist<compactvenue>(); public void add(compactvenue venue){ venues.add(venue); } @suppresswarnings("unchecked") public list<compactvenue> getvenues(){ collections.sort(venues, new objectcomparator()); return venues; } }
objectcomparable .java
import java.util.comparator; import fi.foyt.foursquare.api.entities.compactvenue; import fi.foyt.foursquare.api.entities.compactvenue; import fi.foyt.foursquare.api.entities.location; public class objectcomparator implements comparator{ public int compare(object obj1, object obj2) { if (obj1 instanceof compactvenue && obj2 instanceof compactvenue){ compactvenue v1 = (compactvenue) obj1; compactvenue v2 = (compactvenue) obj2; double r = v1.getlocation().getdistance() - v2.getlocation().getdistance(); if (r > 0){ return 1; } else if (r < 0){ return -1; } } return 0; } }
the output getting here is:
not null null exception in thread "main" java.lang.nullpointerexception @ sample.searchvenues(sample.java:38) @ sample.main(sample.java:20)
can please tell me doing wrong here?? how can print venues on given co ordinates??
Comments
Post a Comment