简体   繁体   English

我在运行 kotlin 项目时遇到这些错误

[英]I am getting these errors while running kotlin project

I am getting these errors while running the application.我在运行应用程序时遇到这些错误。 Can someone help to fix the bug.有人可以帮助修复错误。

Process: app.errandel.android, PID: 29755
java.lang.IndexOutOfBoundsException: Index: 25, Size: 25

You have two lists of data to pull from, but you arbitrarily pull from both lists using the position , which may be bigger than either of them since getItemCount() returns the combined size of both lists.您有两个要从中提取的数据列表,但是您可以使用position从两个列表中任意提取,这可能比其中任何一个都大,因为getItemCount()返回两个列表的组合大小。

You need to decide which list to pull from based on how big the position is.您需要根据 position 的大小来决定从哪个列表中提取。 Something like this:像这样的东西:

override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
    if (position < feedback.size) {
        val feedbackItem = feedback[position]
        itemView.tv_question.text = feedbackItem.questions
        //...
    } else {
        val answersItem = answerss[position - feedback.size]
        holder.itemView.cb_answer.text = answersItem
        //...
    }

}

Since you seem to be using a common layout for both types of list item, you will also need to possibly hide and show parts of the layout in the two respective branches of this if/else statement.由于您似乎对两种类型的列表项都使用了通用布局,因此您还可能需要在 if/else 语句的两个相应分支中隐藏和显示部分布局。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在创建一个项目,并且在运行时遇到麻烦,我试图清理该项目,然后重新启动 - i am creating a project and getting this trouble while running i have tried to cleaning the project relaunching it 编译时出现这些错误 - I am getting these errors while compiling 在 kotlin 中为 SharedPreferences 创建全局变量时出现错误 - I am getting error while creating global variable for SharedPreferences in kotlin 为什么在运行Android应用程序时在DDMS中出现这些错误? - Why am I getting these errors in DDMS when running android application? 为什么我在导入项目时获得无效的项目描述? - Why i am getting invalid project description while importing project? 运行 flutter 应用程序时出现错误 - I am getting error while running my flutter app 运行我的应用程序时,我在android studio中收到此错误 - I am getting this error in android studio while running my app 为什么运行Google Maps活动时出现此错误? - Why i am getting this error while running google maps activity? 在运行android应用程序时,我在控制台中收到以下错误 - while running an android application, i am getting the following error in console 为什么运行我的应用程序一段时间后会出现ConcurrentModificationException? - Why i am getting ConcurrentModificationException after running my app for a while?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM