IllegalArgumentException in Retrofit / must not have replace block

AndroidRetrofit

Android Problem Overview


I have the following code :

    @GET("api.php?company_name={name}")
    Call<Model> getRoms_center(@Query("name") String name);

According to the official docs, I must use @Query, and i'm using it, but i'm getting the following error :

java.lang.IllegalArgumentException: URL query string "company_name={name}" must not have replace block. For dynamic query parameters use @Query.

Android Solutions


Solution 1 - Android

You should do it like that instead:

@GET("api.php")
Call<Model> getRoms_center(@Query("company_name") String name);

Solution 2 - Android

Example URL is: http://service.com/movies/list?movie_lang=hindi

for that URL you can use this:

@GET("http://service.com/movies/list")
Single<JsonElement> getMovieList(@Query("movie_lang") String userLanguage);

Solution 3 - Android

Example Url: https://api.pray.zone/v2/times/today.jsonlatitude=31.3952348&longitude=&elevation=2000&timeformat=1

to pass in retrofit for that URL you can use this:

@GET("today.json")
Call<SalahMainResponse> getSalahTiming(
    @Query("latitude") double latitude,
    @Query("longitude") double longitude,
    @Query("elevation") int elevation,
    @Query("timeformat") int timeformat
);

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJaegerView Question on Stackoverflow
Solution 1 - AndroidGaëtanView Answer on Stackoverflow
Solution 2 - AndroidNarendraView Answer on Stackoverflow
Solution 3 - Androidwaqar saleemView Answer on Stackoverflow