首页 > 解决方案 > 从 Java 类引用/单击时,Kotlin 类崩溃

问题描述

当我尝试单击将引用/调用 kotlin 类以运行的按钮时,应用程序崩溃。我尝试对其进行调试,但出现以下错误。我不知道错误要说什么,也许有人可以帮助我?:

android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
    at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:8798)
    at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:1606)
    at android.view.View.requestLayout(View.java:25390)
    at android.view.View.requestLayout(View.java:25390)
    at android.view.View.requestLayout(View.java:25390)
    at android.view.View.requestLayout(View.java:25390)
    at android.view.View.requestLayout(View.java:25390)
    at android.view.View.requestLayout(View.java:25390)
    at android.widget.RelativeLayout.requestLayout(RelativeLayout.java:380)
    at android.view.View.requestLayout(View.java:25390)
    at androidx.recyclerview.widget.RecyclerView.requestLayout(RecyclerView.java:4412)
    at androidx.recyclerview.widget.RecyclerView$RecyclerViewDataObserver.triggerUpdateProcessor(RecyclerView.java:5582)
    at androidx.recyclerview.widget.RecyclerView$RecyclerViewDataObserver.onItemRangeInserted(RecyclerView.java:5557)
    at androidx.recyclerview.widget.RecyclerView$AdapterDataObservable.notifyItemRangeInserted(RecyclerView.java:12278)
    at androidx.recyclerview.widget.RecyclerView$Adapter.notifyItemInserted(RecyclerView.java:7464)
    at com.example.astrocare.ui.MessagingAdapter.insertMessage(MessagingAdapter.kt:63)
    at com.example.astrocare.ui.Chat_Bot_Main$customBotMessage$1$1.invokeSuspend(Chat_Bot_Main.kt:141)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:241)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:594)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.access$runSafely(CoroutineScheduler.kt:60)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:740)

标签: javakotlin

解决方案


推荐阅读