[英]Kotlin app using recreate() function Error:"java.lang.IllegalStateException: Must be called from main thread"
I get the error"java.lang.IllegalStateException: Must be called from main thread" when using the "recreate()" function to refresh my activity in Kotlin-Android Studio.使用“recreate()”function 刷新我在 Kotlin-Android Studio 中的活动时,出现错误“java.lang.IllegalStateException:必须从主线程调用”。
What is causing the error?是什么导致了错误?
Edit: I solved the problem by running the following instead: " runOnUiThread { recreate() } ", but I still do not understand why I get the error.编辑:我通过运行以下命令解决了问题:“ runOnUiThread { recreate() } ”,但我仍然不明白为什么会出现错误。
Apparently, you were invoking recreate() from a thread other than the UI thread.显然,您是从 UI 线程以外的线程调用 recreate() 的。
You didn't show your code, so we can't tell how you were on this other thread.你没有显示你的代码,所以我们无法知道你在另一个线程上的表现如何。
All UI operations have to be done on the UI, or "main" thread.所有 UI 操作都必须在 UI 或“主”线程上完成。 Therefore the error.因此错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.