android - stackoverflow error using gson -
i trying places of interest , enabled apis "google maps android api & google places api". when post url in web browser api_key.
error message:
" ip, site or mobile application not authorized use api key. request received ip address 212.241.70.124, empty referer".
2nd thing when run code error: " java.lang.stackoverflowerror: stack size 1036kb gson". kindly let me know doing wrong? thankful you!
java code:
public class foodfragment extends fragment { private supportmapfragment mapfragment; @nullable @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view view= inflater.inflate(r.layout.food_layout, null); // getting map here , it's okay. googlemap(); postfetcher postfetcher=new postfetcher(); postfetcher.execute(); return view; } private class postfetcher extends asynctask<void,void,string>{ private static final string tag = "postfetcher"; public static final string server_url = " https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=50&type=restaurant&name=cruise&key=my api key here"; @override protected string doinbackground(void... params) { try { gson gson = new gsonbuilder().create(); foodfragment jsondata = gson.fromjson(server_url, foodfragment.class); system.out.println("data="+jsondata); } catch (exception ex) { log.e(tag, "failed parse json due to: " + ex); } return null; } } }
foodfragment jsondata = gson.fromjson(server_url, foodfragment.class);
foodfragment.class
name of current class file, not java object json represents. second parameter must pojo , first, json string, not url.
it seem need make http request first, may
mapdata map = gson.fromjson(serverresponse, mapdata.class);
after create mapdata
class, of course.
Comments
Post a Comment