Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
572 views
in Technique[技术] by (71.8m points)

java - 我有一个arraylist,它的大小为1,但是当我到达索引0时,我得到= java.lang.IndexOutOfBoundsException:索引:0,大小: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?

(我有一个arraylist,它的大小是1,但是当我到达索引0时,我会得到= java.lang.IndexOutOfBoundsException:索引:0,大小:0谁能告诉我,这是怎么回事?)

  ask by Hamizul Fuad translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

(这样可以避免崩溃。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...