java - FileNotFoundException when trying to find nearby Places with Maps API -


i've been following tutorial in order create app shows nearby places using google maps , places apis. specifically, i'm trying view nearby restaurants or takeaways. is, app displays map fragment, no places show markers.

i have tried increasing radius value, , changing type of ones listed here: https://developers.google.com/places/documentation/supported_types, same filenotfoundexception error. can see what's gone wrong?

here's logcat.

03-13 17:21:51.076: e/googleplayservicesutil(13109): google play services resources not found. check project configuration ensure resources included. 03-13 17:21:51.436: d/dalvikvm(13109): gc_for_alloc freed 2262k, 24% free 8393k/10920k, paused 65ms, total 83ms 03-13 17:21:51.536: d/dalvikvm(13109): gc_for_alloc freed 1339k, 23% free 8409k/10920k, paused 21ms, total 23ms 03-13 17:21:51.586: w/activitythread(13109): classloader.loadclass: class loader returned thread.getcontextclassloader() may fail processes host multiple applications. should explicitly specify context class loader. example: thread.setcontextclassloader(getclass().getclassloader()); 03-13 17:21:52.137: d/dalvikvm(13109): gc_for_alloc freed 739k, 19% free 8928k/10920k, paused 31ms, total 32ms 03-13 17:21:52.387: d/dalvikvm(13109): gc_for_alloc freed 775k, 18% free 9233k/11192k, paused 18ms, total 19ms 03-13 17:21:52.457: w/systemclock(13109): time going backwards: prev 232776411235435(ioctl) vs 232776411021793(ioctl), tid=13531 03-13 17:21:53.308: d/dalvikvm(13109): gc_for_alloc freed 1516k, 19% free 9496k/11604k, paused 21ms, total 21ms 03-13 17:21:53.619: d/exception while downloading url(13109): java.io.filenotfoundexception: https://maps.googleapis.com/maps/api/place/nearbysearch/json??types=meal_takeawaylocation=55.94395494, -3.12815476&radius=10000&sensor=true&key=[my api key] 03-13 17:21:53.629: d/background task(13109): java.lang.nullpointerexception 03-13 17:21:53.659: d/exception(13109): java.lang.nullpointerexception 

and here's code:

public class gpsactivity extends fragmentactivity implements locationlistener{  googlemap mgooglemap; string[] mplacetype=null; string[] mplacetypename=null;  double mlatitude=0; double mlongitude=0;  protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_gps);      mplacetype = getresources().getstringarray(r.array.place_type);     mplacetypename = getresources().getstringarray(r.array.place_type_name);      int status = googleplayservicesutil.isgoogleplayservicesavailable(getbasecontext());     if(status!=connectionresult.success) {         int requestcode = 10;         dialog dialog = googleplayservicesutil.geterrordialog(status, this, requestcode);         dialog.show();     } else {         supportmapfragment fragment = (supportmapfragment) getsupportfragmentmanager().findfragmentbyid(r.id.map);         mgooglemap = fragment.getmap();         mgooglemap.setmylocationenabled(true);         locationmanager locationmanager = (locationmanager) getsystemservice(location_service);         criteria criteria = new criteria();         string provider = locationmanager.getbestprovider(criteria, true);         location location = locationmanager.getlastknownlocation(provider);          if (location!=null) {             onlocationchanged(location);         }          locationmanager.requestlocationupdates(provider, 20000, 0, this);          string type = mplacetype[0];          stringbuilder sb = new stringbuilder("https://maps.googleapis.com/maps/api/place/nearbysearch/json?");         sb.append("?types=meal_takeaway");         sb.append("location="+mlatitude+", "+mlongitude);         sb.append("&radius=10000");         sb.append("&sensor=true");         sb.append("&key=[my api key]");          placestask placestask = new placestask();         placestask.execute(sb.tostring());     } }  public void onlocationchanged(location location) {     mlatitude = location.getlatitude();     mlongitude = location.getlongitude();     latlng latlng = new latlng(mlatitude, mlongitude);     mgooglemap.movecamera(cameraupdatefactory.newlatlng(latlng));     mgooglemap.animatecamera(cameraupdatefactory.zoomto(12)); }  protected void onpostexecute(list<hashmap<string,string>> list) {     mgooglemap.clear();     (int i=0; i<list.size(); i++) {         markeroptions markeroptions = new markeroptions();         hashmap<string,string> hmplace = list.get(i);         double lat = double.parsedouble(hmplace.get("lat"));         double lng = double.parsedouble(hmplace.get("lng"));         string name = hmplace.get("meal_takeaway");         string vicinity = hmplace.get("vicinity");         latlng latlng = new latlng(lat, lng);         markeroptions.title(name+" : "+vicinity);         mgooglemap.addmarker(markeroptions);     } }  @override public void onproviderdisabled(string provider) {     // todo auto-generated method stub  }  @override public void onproviderenabled(string provider) {     // todo auto-generated method stub  }  @override public void onstatuschanged(string provider, int status, bundle extras) {     // todo auto-generated method stub  } }   class placestask extends asynctask<string,integer,string> { string data = null;  private string downloadurl(string strurl) throws ioexception {     string data = "";     inputstream istream = null;     httpurlconnection urlconnection = null;     try {         url url = new url(strurl);         urlconnection = (httpurlconnection) url.openconnection();         urlconnection.connect();         istream = urlconnection.getinputstream();         bufferedreader br = new bufferedreader(new inputstreamreader(istream));         stringbuffer sb = new stringbuffer();         string line = "";         while ( ( line = br.readline()) !=null) {             sb.append(line);         }         data = sb.tostring();         br.close();     } catch (exception e) {         log.d("exception while downloading url", e.tostring());     } {         istream.close();         urlconnection.disconnect();     }     return data; }  protected string doinbackground(string... url) {     try {         data = downloadurl(url[0]);     } catch(exception e) {         log.d("background task", e.tostring());     }     return data; }  protected void onpostexecute(string result) {     parsertask parsertask = new parsertask();     parsertask.execute(result); } } 

thanks, i'd appreciate help.

edit: exception gone, markers still aren't showing on map.

looks url builder broken. have:

stringbuilder sb = new stringbuilder("https://maps.googleapis.com/maps/api/place/nearbysearch/json?");         sb.append("?types=meal_takeaway");         sb.append("location="+mlatitude+", "+mlongitude);         sb.append("&radius=10000");         sb.append("&sensor=true");         sb.append("&key=[my api key]"); 

this means have two ? between json , types, , no & between types=meal_takeaway , location. fix so:

stringbuilder sb = new stringbuilder("https://maps.googleapis.com/maps/api/place/nearbysearch/json?");         sb.append("types=meal_takeaway");         sb.append("&location="+mlatitude+","+mlongitude);         sb.append("&radius=10000");         sb.append("&sensor=true");         sb.append("&key=[my api key]"); 

(note: changes in first 2 sb.append() invocations -- removed space)

fwiw, easier in long run use volley or similar json requests, rather downloading url , parsing separately.


Comments