简体   繁体   English

如何添加到二维ArrayList的索引

[英]How can I add to an index of a 2 dimensional ArrayList

Can anyone tell me how to add a new item to an index of a 2 dimensional ArrayList. 谁能告诉我如何将新项目添加到二维ArrayList的索引中。 The links click here do not resolve my problem. 单击此处的链接不能解决我的问题。

My code to add was the following: 我要添加的代码如下:

wq.get(donsay).set(wq.get(donsay).size(), sil5);

which causes the following exception => 这导致以下异常=>

java.lang.RuntimeException: Unable to start activity ComponentInfo{chessactivesekizsatirvetekliarray.com.sekizsatirvetekliarray/chessactivesekizsatirvetekliarray.com.sekizsatirvetekliarray.MainActivity}: java.lang.StringIndexOutOfBoundsException: length=2; index=3

Thank you all in advance... 谢谢大家...

set() method of ArrayList expects an index less than size. ArrayList的set()方法期望索引小于大小。 Use add() method instead: 使用add()方法代替:

wq.get(donsay).add(wq.get(donsay).size(), sil5);

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM