https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
n

nestserau

12/17/2018, 9:59 AM
The second issue is an exception inside of ktor when I try to work with HttpClient:
Copy code
kotlin.ClassCastException: null cannot be cast to io.ktor.client.call.HttpClientCall
        at 0   test.kexe                           0x000000010f30b976 kfun:kotlin.Exception.<init>(kotlin.String?)kotlin.Exception + 70
        at 1   test.kexe                           0x000000010f30b896 kfun:kotlin.RuntimeException.<init>(kotlin.String?)kotlin.RuntimeException + 70
        at 2   test.kexe                           0x000000010f3a8206 kfun:kotlin.ClassCastException.<init>(kotlin.String?)kotlin.ClassCastException + 70
        at 3   test.kexe                           0x000000010f3b2cfb ThrowClassCastException + 379
        at 4   test.kexe                           0x000000010f3dcb23 CheckInstance + 67
        at 5   test.kexe                           0x000000010f4e5706 kfun:io.ktor.client.HttpClient.$execute$COROUTINE$1.invokeSuspend(kotlin.Result<kotlin.Any?>)kotlin.Any? + 422
        at 6   test.kexe                           0x000000010f4e5802 kfun:io.ktor.client.HttpClient.execute(io.ktor.client.request.HttpRequestBuilder)io.ktor.client.call.HttpClientCall + 130
...
I’ve read earlier in this channel that it can be related to the version of Kotlin that I’m using (1.3.11), but the problem is, I cannot switch to 1.3.10 easily, because if I do, then it starts complaining about
platform.CoreCrypto
not being available. Does anyone know for sure that this error is related to Kotlin version or something else? How I use
HttpClient
is very simple:
Copy code
suspend fun <T> send(message: MessageStrategy<T>): MessageResult<T> {

        val request = message.buildRequest()
        val token = session.state.sessionKey
        ...

        val call = client.call(session.host) {
            method = <http://HttpMethod.Post|HttpMethod.Post>
            body = {
                val encodedMessage = request.record.encode()
                val bytes = ByteArray(encodedMessage.size) { encodedMessage[it].toByte() }
                ByteArrayContent(bytes)
            }
        }

        ...
        return ...
    }
}
m

msink

12/17/2018, 10:20 AM
Don't remember where I saw this, but there was some bug in ktor 1.0.1, maybe 1.0.0 will work for you.
n

nestserau

12/17/2018, 10:43 AM
Switching to 1.0.0 was helpful on the one side, but I guess I still have to go to 1.3.10, as was adivsed to other people, because in the case of the simplest call I get that “frozen object exception”.
I understood my mistake. I formed the request incorrectly. Now that I’ve fixed it, I don’t get that cast exception anymore.
2 Views