简体   繁体   English

我有一个数组列表,它的大小为 1,但是当我到达索引 0 时,我得到 = java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

[英]I have an arraylist and its size is 1, but when i get at index 0, i get = java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
    VideoTask videoTask =  new VideoTask(paccakModel, childPosition, video);
    videoTask.execute();

    ArrayList<VideoModelXml> test = videoTask.getVideoModelXmls();
    test.get(0);

   video.setVideoPath(test.get(0).getUrlVideo());
   video.start();
    return true;
}

I have an arraylist and its size is 1, but when i get at index 0, i get = java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 can anybody tell me, what is going on?我有一个数组列表,它的大小是 1,但是当我到达索引 0 时,我得到 = java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 谁能告诉我,这是怎么回事?

The reason for your issue is videoTask.getVideoModelXmls() returns nothing.您的问题的原因是videoTask.getVideoModelXmls()不返回任何内容。 It should be empty.它应该是空的。 If you want to avoid the crash如果你想避免崩溃

ArrayList<VideoModelXml> test = videoTask.getVideoModelXmls();
if (test .size() > 0){
test.get(0);

   video.setVideoPath(test.get(0).getUrlVideo());
   video.start();
}

Which will avoid your crash.这将避免你的崩溃。

暂无
暂无

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

相关问题 我遇到此错误java.lang.IndexOutOfBoundsException:索引:0,大小:0 - I am having this error java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 java.lang.IndexOutOfBoundsException: Index: 1, Size: 0 at java.util.ArrayList.get(ArrayList.java:437) - java.lang.IndexOutOfBoundsException: Index: 1, Size: 0 at java.util.ArrayList.get(ArrayList.java:437) java.lang.IndexOutOfBoundsException: Index: 2, Size: 1 at java.util.ArrayList.get(ArrayList.java:437) - java.lang.IndexOutOfBoundsException: Index: 2, Size: 1 at java.util.ArrayList.get(ArrayList.java:437) java.lang.IndexOutOfBoundsException:索引:0,大小:0 在 java.util.ArrayList.get - java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at java.util.ArrayList.get java.lang.IndexOutOfBoundsException:无效的索引2,Arraylist中的大小为2? - java.lang.IndexOutOfBoundsException: Invalid index 2, size is 2 in Arraylist? java.lang.IndexOutOfBoundsException:使用ArrayList时索引:0,大小:0 - java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 while working with ArrayList “线程”main“中的异常 java.lang.IndexOutOfBoundsException: Index: 0, Size: 0” with ArrayList? - “Exception in thread ”main“ java.lang.IndexOutOfBoundsException: Index: 0, Size: 0” with ArrayList? java.lang.IndexOutOfBoundsException:索引:1,大小:1 - java.lang.IndexOutOfBoundsException: Index: 1, Size: 1 java.lang.IndexOutOfBoundsException:索引:2,大小:0 - java.lang.IndexOutOfBoundsException: Index: 2, Size: 0 java.lang.IndexOutOfBoundsException:索引:1,大小:1 onBindViewHolder - java.lang.IndexOutOfBoundsException: Index: 1, Size: 1 onBindViewHolder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM