list.remove(index)返回flase,移除失败

简介: list.remove(index)返回flase,移除失败

简述代码:


在Adapter中点击删除用观察者模式传一个index给Activity,在Activity中根据index移除list中的值并更新,最后上传


逻辑没有问题,但是在移除的时候出现问题了,index是接收到了,但是并不能移除。那原因就在移除上了

image.png

重点来了:


此处remove有两个方法,一个传入int,一个传入Object

Integer index = (Integer) aObject;

我是用Integer接收的index,并不是int,所以传进去的话,list会以为是object,所以返回值是boolean,


所以,知道原因了解决起来就很简单了


只需要把index转为int就行了。


mImageList.remove(index.intValue());

目录
相关文章
|
机器学习/深度学习 文字识别 开发者
使用OCR库Pix2Text执行p2t.recognize()时出现list index out of range的错误信息(附有Pix2Text识别图片内容和laTex公式的代码)
有时候报错并不是你代码有问题,源码出错也是很常见的情况,比如之前使用mxgraph也出现了不知名bug,最后也是修改的源码解决的。有疑问欢迎交流~ 博客不应该只有代码和解决方案,重点应该在于给出解决方案的同时分享思维模式,只有思维才能可持续地解决问题,只有思维才是真正值得学习和分享的核心要素。如果这篇博客能给您带来一点帮助,麻烦您点个赞支持一下,还可以收藏起来以备不时之需,有疑问和错误欢迎在评论区指出~
|
存储 索引 Python
【Python】已解决:IndexError: list index out of range
【Python】已解决:IndexError: list index out of range
4339 1
|
索引 Python
row[i] = col[j] = TrueIndexError: list assignment index out of range
row[i] = col[j] = TrueIndexError: list assignment index out of range
337 1
|
开发者 Python
【Python】已解决:TypeError: descriptor ‘index‘ for ‘list‘ objects doesn‘t apply to a ‘str‘ object
【Python】已解决:TypeError: descriptor ‘index‘ for ‘list‘ objects doesn‘t apply to a ‘str‘ object
810 0
【已解决】AttributeError: ‘Index‘ object has no attribute ‘to_list‘
【已解决】AttributeError: ‘Index‘ object has no attribute ‘to_list‘
|
存储 算法 索引
倒排索引的数据结构:Term index、Term Dictionary、Posting List
倒排索引的数据结构:Term index、Term Dictionary、Posting List
倒排索引的数据结构:Term index、Term Dictionary、Posting List
成功解决sys.argv[1] IndexError: list index out of range错误
成功解决sys.argv[1] IndexError: list index out of range错误
成功解决sys.argv[1] IndexError: list index out of range错误
Python: list of list, 将内部 list 的 index 作为该内部 list 中每个元素的分类标签
Python: list of list, 将内部 list 的 index 作为该内部 list 中每个元素的分类标签
|
安全 Java
java线程之List集合并发安全问题及解决方案
java线程之List集合并发安全问题及解决方案
2415 1

热门文章

最新文章