ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) (at <eae584ce26bc40229c1b1aa476bfa589>:0) System.ThrowHelper.ThrowArgumentOutOfRangeException () (at <eae584ce26bc40229c1b1aa476bfa589>:0) System.Collections.Generic.List`1[T].get_Item (System.Int32 index) (at <eae584ce26bc40229c1b1aa476bfa589>:0) GameManager1.SetShop () (at Assets/Lesson1/GameManager1.cs:23) UIManager1.Start () (at Assets/Lesson1/UIManager1.cs:14)
时间: 2023-06-11 08:09:34 浏览: 100
这个错误是由于你的代码尝试访问了一个超出集合大小范围的索引引起的。具体地说,在你的GameManager1类的第23行代码中,你尝试访问一个List对象的元素,但是该元素的索引超出了List对象的大小范围。
你需要检查集合的大小和索引的取值范围,并确保它们是正确的。你可以使用List的Count属性来获取集合中元素的数量,并始终确保你的索引值在0和Count-1之间。
相关问题
System.ArgumentOutOfRangeException:“Index was out of range. Must be non-negative and less than the size of the collection. Arg_ParamName_Name”
这个异常表示索引超出了集合的范围,必须是非负数并且小于集合的大小。Arg_ParamName_Name表示参数名为Name。这种异常通常是因为你试图访问一个不存在的元素或者使用了错误的索引值。你需要检查你的代码中涉及到集合的部分,确保访问元素时使用的索引值是正确的,并且没有越界。如果你需要更多的帮助,请提供更多的上下文和代码。
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
这个错误通常是因为你访问了一个集合中不存在的索引,也就是说你要么访问了一个负数索引,或者是一个大于等于集合大小的索引。你需要确保你的代码中访问的索引是合法的,也就是在集合的范围内。你可以检查一下集合的大小,并且确保它不为空。如果你还是无法解决这个问题,你可以把出错的代码或者堆栈信息贴出来,这样我就可以更好地帮助你了解问题的原因。