I want to use
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val json = URL("https://my-api-url.com/something").readText()
simpleTextView.setText(json)
}
but this fatal error occurs
FATAL EXCEPTION: main
Process: com.mypackage.randompackage, PID: 812
java.lang.RuntimeException: Unable to start activity ComponentInfo{ ***.MainActivity}: android.os.NetworkOnMainThreadException
How can I simply read a JSON from a URL link?
The package of the async
function doesn't exist.