Akshay Sood
Akshay Sood

Reputation: 150

Android Retrofit Error

I have made an application that will make a request with some parameters to Google API that will return JSON as a response.. The problem is that this request will be made every 2 seconds. So now here my logcat is showing some error and calling failure() everytime

here is my logcat:

09-14 18:03:55.338   8080-10980/com.example.akshay.retrofitgsonjsonarray D/Retrofit﹕ ---- ERROR
09-14 18:03:55.348   8080-10980/com.example.akshay.retrofitgsonjsonarray D/Retrofit﹕ java.lang.IllegalArgumentException: api.getData: URL query string "path={latlong}&interpolate=true&key=AIzaSyDAsAs9k2dQ6aDMUlgLcE-dTxAOxMtADTU" must not have replace block. For dynamic query parameters use @Query.
            at retrofit.RestMethodInfo.methodError(RestMethodInfo.java:107)
            at retrofit.RestMethodInfo.parsePath(RestMethodInfo.java:210)
            at retrofit.RestMethodInfo.parseMethodAnnotations(RestMethodInfo.java:149)
            at retrofit.RestMethodInfo.init(RestMethodInfo.java:117)
            at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:294)
            at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
            at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
            at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at retrofit.Platform$Android$2$1.run(Platform.java:142)
            at java.lang.Thread.run(Thread.java:818)
09-14 18:03:55.348   8080-10980/com.example.akshay.retrofitgsonjsonarray D/Retrofit﹕ ---- END ERROR

Every time the value of logcat will be changed so I am confused what is going wrong.

The problem is here I guess but I am not able to sort it out

package com.example.akshay.retrofitgsonjsonarray;
import retrofit.Callback;
import retrofit.http.GET;
import retrofit.http.Query;

/**
 * Created by Akshay on 9/8/2015.
 */
public interface api {
    @GET("/snapToRoads?path={latlong}&interpolate=true&key=KEY")
    public void getData(@Query("latlong") String latlng, Callback<SnappedPointsContainer> response);
}

any help .. thanks

Upvotes: 1

Views: 2267

Answers (2)

Rajan Maurya
Rajan Maurya

Reputation: 634

It is good to do like above answer for small data fetch like you are fetching data from one and two directories of your Api but for dynamic doing all thing . you need to put your base url in string.xml Like: example.com

And Your Interface

public interface api {
@GET("/snapToRoads")
public void getData(@Query("path") String latlng, @Query("interpolate") boolean interpolate , @Query("key") String key Callback<SnappedPointsContainer> response);}

SnappedPointsContainer Pojo in which data come

Don't need to use {anything} Path parameter in this , here you are sending three query only good luck ...

Upvotes: 1

Ramesh
Ramesh

Reputation: 1287

As your error says, api.getData: URL query string "path={latlong}&interpolate=true&key=GOogle api key" must not have replace block. For dynamic query parameters use @Query

you already had latlong as query parameter with latlong so you can remove path from hardcoded url query string and rename the query field as path.

@GET("/snapToRoads?interpolate=true&key="googlekey") 
public void getData(@Query("path") String latlng, Callback<SnappedPointsContainer> response);

On a side note : You should not sharing your google api key publicly.

Upvotes: 2

Related Questions