19

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")
CHALA19X
  • 311
  • 2
  • 7

1 Answers1

27

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!

Segun Famisa
  • 448
  • 5
  • 7
  • Yes that solved that issue which i thought wascausing me this problem of not bein able to connect to my local host tho am able to connect to an online one – CHALA19X Jul 06 '19 at 13:20
  • 1
    For more details, see this upgrade guide: http://square.github.io/okhttp/upgrading_to_okhttp_4/ – Jesse Wilson Jul 06 '19 at 17:44