Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index') at System.Collections.Generic.List`1.get_Item(Int32 index)
时间: 2024-04-26 13:26:59 浏览: 26
这个错误提示是在使用List时,访问了一个不存在的元素的索引导致的。可能是你在访问List中的某个元素时,给定了一个超出List长度范围的索引值,或者在对List进行操作过程中,List的长度发生了变化,导致之前存储的索引值已经不再有效了。建议你检查一下代码,看看是否存在这样的情况。如果有,需要对代码进行相应的调整。
相关问题
unity报错ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index System.Collections.Generic.List`1[T].get_Item (System.Int32 index) (at <9aad1b3a47484d63ba2b3985692d80e9>:0) H
这个错误通常是因为你访问了一个集合中不存在的索引,也就是说你要么访问了一个负数索引,或者是一个大于等于集合大小的索引。你需要确保你的代码中访问的索引是合法的,也就是在集合的范围内。你可以检查一下集合的大小,并且确保它不为空。如果你还是无法解决这个问题,你可以把出错的代码或者堆栈信息贴出来,这样我就可以更好地帮助你了解问题的原因。
cont.collections[i].get_paths()[0].vertices IndexError: list index out of range
这个错误通常表示你尝试访问一个空列表中的元素。也就是说,你在代码中使用了 `[]` 索引运算符来获取一个列表中的元素,但是这个列表中没有任何元素,因此 Python 抛出了 `IndexError: list index out of range` 异常。
在你的代码中,你可能需要检查一下使用 `get_paths()` 方法返回的 `cont.collections[i]` 对象是否为空,或者使用 `if` 语句来检查是否存在索引为 0 的路径。
例如:
```
paths = cont.collections[i].get_paths()
if paths:
vertices = paths[0].vertices
# 处理 vertices
else:
# 处理列表为空的情况
```
这样可以避免出现索引错误异常。
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)