No Retrofit Annotation Found For Parameter #1

Viewed 1052

Here is my interface code. But it is giving error at @Field

@POST("login")
    @FormUrlEncoded
    fun login(@Field email : String, password: String) : Call<LoginResponse>

Calling Function:

private fun login() {

    val callback = object : MyCallback<LoginResponse>() {

        override fun onSuccess(response: LoginResponse) {
            Log.d("family", "Login Success.")
        }

        override fun onFail(error: ErrorModel) {
            Log.d("family", "Login Failed.")
        }
    }

    RestClientManager.getInstance(context).login("jhon@family-live.com", "123456789", callback)
}

Here is my error : java.lang.IllegalArgumentException: No Retrofit annotation found. (parameter #1) for method RestService.login

2 Answers

Use This

@POST("login")
@FormUrlEncoded
fun login(@Field email : String, @Field password: String) : Call<LoginResponse>

Please check the api call on Postman and check the fields name in proper manner and put the field name in bracket which will assign value to that field. read the official documentation URL manipulation.

@POST("login")
@FormUrlEncoded
fun login(@Field("email") email : String, @Field("password") password: String) : Call<LoginResponse>
Related