No Retrofit annotation found. (parameter #1)

前端 未结 14 1871
长发绾君心
长发绾君心 2020-12-09 00:50

I want get RSS code from a URL with Retrofit and if I enter url staticly in the get annotation everything is OK but with dynamic url I get an error.

My

相关标签:
14条回答
  • 2020-12-09 00:59

    This happened to me when I was using suspend functions in the network service interface like so.

    interface Service {
        @GET("chapters")
        suspend fun fetchChapters() : List<NetworkChapter>
    

    I solved it by doing 2 things. 1. Using Gson instead of Moshi library. Remove moshi converter from retrofit and use Gson converter. 2. Removing coroutine converter factory from retrofit. I think this one was the main problem.

    0 讨论(0)
  • 2020-12-09 01:03

    Also make sure you add @Query or @Field for all the parameters , depending on whether you issuing GET/POST.

    eg:

    @GET("/api/Books/GetAll")
    void GetRecentBooks(@Query int Offset, Callback<List<Book>> cb);
    
    0 讨论(0)
  • 2020-12-09 01:03

    Remove from retrofit interface all parameters that not belong to this.

    0 讨论(0)
  • 2020-12-09 01:04

    I forgot to add @Field("")

    Previously

       @POST("/api/verify-phone")
        @FormUrlEncoded
        fun sendOTP(phone_number: String): Observable<SignInResponse?>
    

    Fixed

    @POST("/api/verify-phone")
    @FormUrlEncoded
    fun sendOTP(@Field("phone")phone_number: String): Observable<SignInResponse?>
    
    0 讨论(0)
  • 2020-12-09 01:07

    Please check the Path class you are using and make sure that the package is retrofit2.http.Path instead of org.simpleframework.xml.Path. It is a common Retrofit annotation mistake.

    0 讨论(0)
  • 2020-12-09 01:09

    In my case, I just forgot to remove Callback parameter for the service call when I start using retrofit 2. Make sure you didn't do the silly mistake I did.

    0 讨论(0)
提交回复
热议问题