3

I have created a very simple retrofit service and am getting an IllegalArgumentException on my @GET call. For some reason my @Query annotation is not being recognized or accepted but from what I can see there is absolutely nothing wrong. Please have a look and tell me if I have missed something...thank you.

Retrofit object built here

public static Retrofit getRequest(@NonNull Context context){

    OkHttpClient client = new OkHttpClient();
Retrofit retrofit = new 
    Retrofit.Builder().baseUrl("https://blah.blah.com/").client(client).addConverterFactory(GsonConverterFactory.create()).build();
    return retrofit;
}

Service

public interface Request
{
    String SEARCHPATH = "...";
final static String KEY = "...";

@GET(SEARCHPATH)
Call<Results> getRes(@Query("api-key") String key, @Query("q") String q);
}

Call

private void initSearch(String term){
    retrofit = RequestBuilder.getRequest(this);
    req = retrofit.create(Request.class);
result = req.getRes(Request.KEY, "string");
result.enqueue(new Callback(){
    @Override
    public void onResponse(Call<Results> call, Response<Results> response){
        Log.d("data", String.valueOf(response.body().toString()));
    }
        @Override
    public void onFailure(Call<Results> call, Throwable t) {
    Log.d("data", t.getMessage());
    }
});
}

Gradle build

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
    applicationId "com.mycompany.newssearch"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 
'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-compat:27.1.1'
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
compile 'com.squareup.okhttp:okhttp:2.7.0'
compile 'com.android.support:support-core-utils:27.1.1'
}

Exception

java.lang.IllegalArgumentException: No Retrofit annotation found. 
(parameter #1)
user3167555
  • 73
  • 1
  • 8

1 Answers1

2

Make query like this way:

@GET("details/json")
Call<PlaceDetailsResponse> getPlaceDetailsData(
    @Query("placeid") String placeid,
    @Query("key") String key
);

Make sure define query in key is same as url in above query make url like

details/json?placeid=...&key=...
Boken
  • 4,825
  • 10
  • 32
  • 42