Shahek Shahek - 1 year ago 188
Android Question

stackoverflow error using gson

I am trying to get places of interest and enabled APIS are "google maps android API & google places API". When I post the url in web browser with my API_Key.

Error message:

" This IP, site or mobile application is not authorized to use this API key. Request received from IP address, with empty referer".

2nd thing when i run this code then i get error:
" java.lang.StackOverflowError: stack size 1036KB gson".
Kindly let me know what I am doing wrong? I would be really thankful to you!

Java Code:

public class FoodFragment extends Fragment {

private SupportMapFragment mapfragment;

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

View view= inflater.inflate(R.layout.food_layout, null);

// I am getting Map here and it's okay.

PostFetcher postfetcher=new PostFetcher();

return view;

private class PostFetcher extends AsyncTask<Void,Void,String>{

private static final String TAG = "PostFetcher";
public static final String SERVER_URL = ",151.1957362&radius=50&type=restaurant&name=cruise&key=My APi key here";

protected String doInBackground(Void... params) {

try {

Gson gson = new GsonBuilder().create();
FoodFragment jsondata = gson.fromJson(SERVER_URL, FoodFragment.class);


} catch (Exception ex) {
Log.e(TAG, "Failed to parse JSON due to: " + ex);
return null;



Answer Source
FoodFragment jsondata = gson.fromJson(SERVER_URL, FoodFragment.class);

FoodFragment.class is the name of your current class file, not a Java object that the JSON represents. That second parameter must be a POJO and the first, a JSON string, not a URL.

It would seem you need to make a HTTP request first, then you may do

MapData map = gson.fromJson(serverResponse, MapData.class);

After you create a MapData class, of course.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download