M. Taufiq Hidayat
M. Taufiq Hidayat

Reputation: 1

java.lang.IllegalArgumentException error on Retrofit

i want to get a data on Internet use Retrofit Library my code look like this :

@GET("?key={key}&q={quotes}")
Call<List<Pixabay.hits>> getTheData(@Query("key") String key, @Query("quotes") String quotes);

java.lang.IllegalArgumentException: URL query string key={key}&q={quotes} must not have replace block. For dynamic query parameters use @Query. for method api.getTheData

I get that problem, how to solve this? thank you.

Upvotes: 0

Views: 276

Answers (2)

Choim
Choim

Reputation: 392

you don't have to write query parameters in your path. @Query will do that for you.

replace

@GET("?key={key}&q={quotes}")

with

@GET("/")

Precisely, {something} parameter can be used only in path variable. For example,

@GET("/key/{key}")

In this case, you can use @Path annotation instead of @Query.

Upvotes: 1

Farid Haq
Farid Haq

Reputation: 4191

If you specify @GET("key?a=5"), then any @Query("b") must be appended using &, producing something like key?a=5&b=7.

If you specify @GET("key"), then the first @Query must be appended using ?, producing something like key?b=7.

So in your case no need to implement here like ?key={key}&q={quotes} just add your domain @GET("your_domain/")

Upvotes: 0

Related Questions