[英]java.lang.RuntimeException error with Jsoup
I've import Jsoup into my project, everything is okay until this time.我已经将 Jsoup 导入到我的项目中,直到此时一切正常。 But as I trying to connect and URL, I got this error:
但是当我尝试连接和 URL 时,我收到了这个错误:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.test/com.example.test.MainActivity}:android.os.NetworkOnMainThreadException
I've added permission:我添加了权限:
<uses-permission android:name="android.permission.INTERNET"/>
This line causes the error:此行导致错误:
var doc = Jsoup.connect("https://google.com").get()
That's it.而已。 I've searched on stack overflow but I can not solve it.
我已经搜索了堆栈溢出,但我无法解决它。
Call it in the new Thread or Coroutine.在新的线程或协程中调用它。 For example:
例如:
Thread {
var doc = Jsoup.connect("https://google.com").get()
}.run()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.