I have this code:
lifecycleScope.launch(Dispatchers.Default) {
val specialMessage = URL("https://finepointmobile.com/api/inventory/v1/message").readText()
d("Globby", "The message is: $specialMessage")
lastSavedProduct.text = specialMessage //line 41
}
But when executing I get the following error:
ERROR : android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
at com.example.MainActivity$onCreate$2.invokeSuspend(MainActivity.kt:41)
I tried changing lifecycleScope.launch(Dispatchers.IO)
to lifecycleScope.launch(Dispatchers.Default)
but it doesn't work.