Sad*_*ife 18 arraylist indexoutofboundsexception kotlin
我有一个空的数组列表:
var mylist: ArrayList<Int> = ArrayList()
Run Code Online (Sandbox Code Playgroud)
当我想在其中设置值时,我收到此错误:
java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
Run Code Online (Sandbox Code Playgroud)
问题是:我如何初始化我的清单?
LuC*_*Cio 33
根据api-doc:
val list = arrayListOf<Int>()
Run Code Online (Sandbox Code Playgroud)
这里也提到了:如何在Kotlin中初始化List? .
Szy*_*ber 16
我建议你写
var myList: ArrayList<Int> = arrayListOf()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18700 次 |
| 最近记录: |