Hi guys can anyone help me? I am using koin for di...
# multiplatform
e
Hi guys can anyone help me? I am using koin for di in my KMP project (android & desktop), but when I consume an API in my desktop app with ktor I have this error... I think it is the logger:
Copy code
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See <http://www.slf4j.org/codes.html#StaticLoggerBinder> for further details.
Exception in thread "AWT-EventQueue-0" java.nio.channels.UnresolvedAddressException
	at java.base/sun.nio.ch.Net.checkAddress(Net.java:149)
	at java.base/sun.nio.ch.Net.checkAddress(Net.java:157)
	at java.base/sun.nio.ch.SocketChannelImpl.checkRemote(SocketChannelImpl.java:816)
	at java.base/sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:839)
	at io.ktor.network.sockets.SocketImpl.connect$ktor_network(SocketImpl.kt:44)
	at io.ktor.network.sockets.ConnectUtilsJvmKt.connect(ConnectUtilsJvm.kt:21)
	at io.ktor.network.sockets.TcpSocketBuilder.connect(TcpSocketBuilder.kt:37)
	at io.ktor.client.engine.cio.ConnectionFactory.connect(ConnectionFactory.kt:30)
	at io.ktor.client.engine.cio.Endpoint$connect$2$connect$1.invokeSuspend(Endpoint.kt:207)
	at io.ktor.client.engine.cio.Endpoint$connect$2$connect$1.invoke(Endpoint.kt)
	at io.ktor.client.engine.cio.Endpoint$connect$2$connect$1.invoke(Endpoint.kt)
	at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturnIgnoreTimeout(Undispatched.kt:72)
	at kotlinx.coroutines.TimeoutKt.setupTimeout(Timeout.kt:148)
	at kotlinx.coroutines.TimeoutKt.withTimeoutOrNull(Timeout.kt:104)
	at io.ktor.client.engine.cio.Endpoint.connect(Endpoint.kt:215)
	at io.ktor.client.engine.cio.Endpoint.makeDedicatedRequest(Endpoint.kt:100)
	at io.ktor.client.engine.cio.Endpoint.execute(Endpoint.kt:64)
	at io.ktor.client.engine.cio.CIOEngine.execute(CIOEngine.kt:79)
	at io.ktor.client.engine.HttpClientEngine$executeWithinCallContext$2.invokeSuspend(HttpClientEngine.kt:99)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
	at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:111)
	at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:99)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:585)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:802)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:706)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:693)
	Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@299cf502, Dispatchers.Main.immediate]
m
Looks like your Desktop app is not connected to the internet?
Or another kind of connectivity error
m
I think i had the same issue on Android (or desktop, cannot remember), and i had to manually add the dependency for this
org.slf4j….StaticLoggerBinder
to the build gradle for the respective platform. I don’t remember exactly but i know that googling this StaticLoggerBinder issue led me to stackoverflow where the import was listed. Good luck!
Found it, this i had to add to my Android dependency block to fix the issue:
dependencies {
……
implementation("org.slf4j:slf4j-simple:1.7.32")
}
m
@Max that's for the first 3 lines but the exception after that is unrelated IMO
e
Thanks for your help. I resolved the logger problem but I'm still encountering a connectivity error. I'm not sure why it's happening, since I do have connectivity from my mobile app.
I already found the problem, I was implementing two different ktor clients (cio & okhttp) in my dependencies, thanks for all.