简体   繁体   English

Kotlin 应用程序使用 recreate() function 错误:“java.lang.IllegalStateException:必须从主线程调用”

[英]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.

相关问题 kotlin 中的线程“主”java.lang.IllegalStateException 中的异常 - Exception in thread “main” java.lang.IllegalStateException in kotlin java.lang.IllegalStateException: TextView 不能为 null (Android/Kotlin) - java.lang.IllegalStateException: TextView must not be null (Android/Kotlin) Kotlin Android扩展:java.lang.IllegalStateException:视图不能为null - Kotlin Android Extensions : java.lang.IllegalStateException: view must not be null java.lang.IllegalStateException:Kotlin NavigationComponent App 中没有当前导航节点 - java.lang.IllegalStateException: no current navigation node in Kotlin NavigationComponent App Android Kotlin:java.lang.IllegalStateException - Android Kotlin: java.lang.IllegalStateException java.lang.IllegalStateException:[TextView]不能为null - java.lang.IllegalStateException: [TextView] must not be null java.lang.IllegalStateException:cardProductItem不能为null - java.lang.IllegalStateException: cardProductItem must not be null java.lang.IllegalStateException:nicknameTextView 不能为 null - java.lang.IllegalStateException: nicknameTextView must not be null Kotlin-java.lang.IllegalStateException:ViewStub必须具有非null的ViewGroup viewParent - Kotlin - java.lang.IllegalStateException: ViewStub must have a non-null ViewGroup viewParent 在Kotlin上,杰克逊ObjectMapper.readValue()导致java.lang.IllegalStateException:readValue(content,jacksonTypeRef <T> ())不能为null - On Kotlin jackson ObjectMapper.readValue() causes java.lang.IllegalStateException: readValue(content, jacksonTypeRef<T>()) must not be null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM