Getting an error Using 'body(): ResponseBody?' is an error. moved to val with okhttp

久未见 提交于 2020-06-13 19:24:07

问题


Using response.body() gives me an error of "Using 'body(): ResponseBody?' is an error. moved to val" i tried removing ? but nothing works the error is in body()

        override fun onResponse(call: Call, response: Response) {
            val body = response.body()?.string();

            println(body)
            println("Sucees")

回答1:


It looks like you're using OkHttp 4.0.0.

The response.body() function has been deprecated. Instead, you need to access the body as a val, like this:

override fun onResponse(call: Call, response: Response) {
            val body = response.body?.string();

            println(body)
            println("Sucees")
}

Let me know if that helps!



来源:https://stackoverflow.com/questions/56913085/getting-an-error-using-body-responsebody-is-an-error-moved-to-val-with-ok

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!