Android /改造:“对象不是抽象的,并且没有实现成员”

时间:2019-09-15 18:12:47

标签: android kotlin retrofit retrofit2

我正在尝试创建POST请求,以使用JSON中的电子邮件和密码参数登录用户。

我遇到以下错误:

enter image description here

AuthService.kt

interface AuthService {

    @POST("/user/signin")
    fun login(@Body request: JSONObject) : Call<PostLoginResponse>

}

PostLoginResponse.kt

data class PostLoginResponse(
    val access_token: String,
    val expires_in: Number,
    val token_type: String
)

LoginActivity.kt

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.login)

        email = findViewById(R.id.input_email)
        password = findViewById(R.id.input_password)

        signinButton = findViewById(R.id.btn_login)
        signinButton.setOnClickListener {
            val authJsonData = JSONObject()
            authJsonData.put("email", email.text.toString().trim())
            authJsonData.put("password", password.text.toString().trim())
            login(authJsonData);
        }

    }

private fun login(jsonData: JSONObject) {

        val call = App.authService.login(jsonData)
        call.enqueue(object : Callback<PostLoginResponse> {

            override fun onResponse(call: Call<PostLoginResponse>, response: Response<PostLoginResponse>) {
                Log.i(TAG, "login() - onResponse() Result = ${response?.body()}")
            }

            override fun onFailure(call: Call<GetSitesResponse>, t: Throwable) {
                Log.e(TAG, "login() - onFailure() ", t)
            }

        })

    }

1 个答案:

答案 0 :(得分:2)

通过call方法将Call<GetSitesResponse>参数类型从Call<PostLoginResponse>更改为onFailure

override fun onFailure(call: Call<PostLoginResponse>, t: Throwable) {
    Log.e(TAG, "login() - onFailure() ", t)
}