https://kotlinlang.org logo
#compose-desktop
Title
# compose-desktop
s

Shubhasai Mohapatra

03/13/2023, 2:18 PM
Hi I new to compose I have written the following code. But while calling the API On button click getting this error. Also I want to know how to Log in compose desktop. Error message in the Thread
🧵 1
Copy code
Exception in thread "DefaultDispatcher-worker-3" java.lang.RuntimeException: Exception while trying to handle coroutine exception
	at kotlinx.coroutines.CoroutineExceptionHandlerKt.handlerException(CoroutineExceptionHandler.kt:38)
	at kotlinx.coroutines.CoroutineExceptionHandlerImplKt.handleCoroutineExceptionImpl(CoroutineExceptionHandlerImpl.kt:52)
	at kotlinx.coroutines.CoroutineExceptionHandlerKt.handleCoroutineException(CoroutineExceptionHandler.kt:33)
	at kotlinx.coroutines.StandaloneCoroutine.handleJobException(Builders.common.kt:193)
	at kotlinx.coroutines.JobSupport.finalizeFinishingState(JobSupport.kt:229)
	at kotlinx.coroutines.JobSupport.tryMakeCompletingSlowPath(JobSupport.kt:906)
	at kotlinx.coroutines.JobSupport.tryMakeCompleting(JobSupport.kt:863)
	at kotlinx.coroutines.JobSupport.makeCompletingOnce$kotlinx_coroutines_core(JobSupport.kt:828)
	at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:100)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
	at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
	at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:749)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
	Suppressed: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $
		at com.google.gson.stream.JsonReader.beginArray(JsonReader.java:349)
		at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:80)
		at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)
		at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:39)
		at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:27)
		at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:225)
		at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:121)
		at okhttp3.RealCall$AsyncCall.execute(RealCall.java:206)
		at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
		at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
		at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
		at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.NoClassDefFoundError: android/os/Build$VERSION
	at kotlinx.coroutines.android.AndroidExceptionPreHandler.handleException(AndroidExceptionPreHandler.kt:49)
	at kotlinx.coroutines.CoroutineExceptionHandlerImplKt.handleCoroutineExceptionImpl(CoroutineExceptionHandlerImpl.kt:48)
	... 15 more
Caused by: java.lang.ClassNotFoundException: android.os.Build$VERSION
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
	... 17 more
Exception in thread "DefaultDispatcher-worker-3" java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $
	at com.google.gson.stream.JsonReader.beginArray(JsonReader.java:349)
	at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:80)
	at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)
	at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:39)
	at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:27)
	at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:225)
	at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:121)
	at okhttp3.RealCall$AsyncCall.execute(RealCall.java:206)
	at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:833)
	Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@694b61b5, <http://Dispatchers.IO]|Dispatchers.IO]>
Caused by: java.lang.NoClassDefFoundError: android/os/Build$VERSION

Caused by: java.lang.ClassNotFoundException: android.os.Build$VERSION
a

Alexander Maryanovsky

03/13/2023, 2:42 PM
Log
is an Android thing
You can’t use it on the desktop
s

Shubhasai Mohapatra

03/13/2023, 2:44 PM
Is there any alternative
a

Alexander Maryanovsky

03/13/2023, 2:45 PM
There are several logging libraries. Log4j maybe
Or, the best logging library in the world:
println()
😉
s

Shubhasai Mohapatra

03/13/2023, 2:50 PM
thanks
but can you just help why this error is coming is there any mistake in the code?
a

Alexander Maryanovsky

03/13/2023, 2:52 PM
The mistake is trying to use some Android code on the desktop.
I can’t quite figure out what, but it crashes on
Copy code
Caused by: java.lang.ClassNotFoundException: android.os.Build$VERSION
so something you’re calling is an Android library that’s trying to check the Android API version.
Check your imports for android code
Log
is definitely one of those, but there may be more
s

Shubhasai Mohapatra

03/13/2023, 2:55 PM
ok so may be it is because of theese errors
Copy code
import androidx.compose.material.Text
import androidx.compose.material.Button
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
a

Alexander Maryanovsky

03/13/2023, 2:56 PM
No, those (
androidx.compose
) are part of compose
s

Shubhasai Mohapatra

03/13/2023, 2:58 PM
because for log i had used
Copy code
import org.jetbrains.skia.impl.Log
13 Views