Search code examples
androidretrofit2

How to fix "No Retrofit annotation found. (parameter #2)"?


I want to send an HTTP post request, everything was fine so far (I sent 10+ requests in this application), but now there is a problem.

I get this error:

E/AndroidRuntime: FATAL EXCEPTION: main
  Caused by: java.lang.IllegalArgumentException: No Retrofit annotation found. (parameter #2)

This is the interface code:

@POST("index.php/web/request")
    Call<MyResponse> getMy(@Header("authorization") String token, MyRequest myRequest);

This is my MainActivity code:

Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("https://link.com/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        service = retrofit.create(MyAPI.class);

        MyRequest myRequest = new MyRequest();

        myRequest.setText(text);

        final Call<MyResponse> myResponseCall = service.getMy(token, myRequest);

Error is in this line:

final Call<MyResponse> myResponseCall = service.getMy(token, myRequest);

Solution

  • you have not annotated the second parameter.... it can be @Body,@Query etc.... add an annotation