Error using Retrofit 2

Asked

Viewed 407 times

0

t={movieName}&apikey=11111" must not have replace block. For Dynamic query Parameters use @Query.

This error happens when trying to fetch a movie by name, I have the codes below, but the error remains:

Retrofit retrofit = new Retrofit.Builder()
        .baseUrl("http://www.omdbapi.com/")
        .addConverterFactory(GsonConverterFactory.create())
        .build();

@GET("?t={movieName}&apikey=11111")
Call<List<MovieResults>> getFilmesByName(@Query("movieName") String movieName);

How to make the movie name dynamic, that is, searched through what is written inside an edittext?

1 answer

3


For this situation you should use the @Path. Example:

@GET("/?t={movieName}&apikey=11111")
Call<List<MovieResults>> getFilmesByName(@Path("movieName") String movieName);

If you do not want to, there is no need to put the parameter in the URL as you are doing explicitly, just use the @query which is inserted automatically. See how it should look:

@GET("/?apikey=11111")
Call<List<MovieResults>> getFilmesByName(@Query("t") String movieName);
  • Path error is the same.

  • @Henriquemendes usually works that way with me. You tried using Query?!

  • It worked now here,with the query this way it passed, I will do some more landmark tests as a response! Thank you!

  • @Henriquemendes Anything, give a touch! = D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.