如何修复 "No Retrofit annotation found. (parameter #2)"?

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

我想发送一个 HTTP post 请求,到目前为止一切正常(我在此应用程序中发送了 10 多个请求),但现在出现了问题。

我收到这个错误:

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

这是接口代码:

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

这是我的 MainActivity 代码:

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);

错误在这一行:

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

将您的接口方法更改为此

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

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

你还没有注释第二个参数....它可以是@Body,@Query等....添加一个注释