StopIteration无法预测的错误

时间:2015-12-11 08:18:53

标签: python python-3.x

此函数给出了不可预知的import java.util.ArrayList; import java.util.Iterator; public class SongGroup extends SongComponent { ArrayList songComponents = new ArrayList(); String groupName; String groupDescription; public SongGroup(String newGroupName, String newGroupDesc){ groupName = newGroupName; groupDescription = newGroupDesc; } public String getGroupName(){ return groupName; } public String getGroupDescription(){ return groupDescription; } // It overrides the add() method from its superclass public void add(SongComponent newSongComp){ songComponents.add(newSongComp); } public void remove(SongComponent newSongComp){ songComponents.remove(newSongComp); } public SongComponent getComponent(int compIndex){ return (SongComponent)songComponents.get(compIndex); } public void displaySongInfo(){ System.out.println( getGroupName() + " " + getGroupDescription()); Iterator songIterator = songComponents.iterator(); while(songIterator.hasNext()){ SongComponent songInfo = (SongComponent)songIterator.next(); songInfo.displaySongInfo(); } } } 错误。我想了解导致这种错误的原因。因为它有时会起作用,有时候不会:

StopIteration

1 个答案:

答案 0 :(得分:4)

{p> StopIteration将由next引发,如果它被赋予空迭代。

如果dimensions中的任何dim_listdim_list中的任何内容都不匹配,您将收到此错误,因为列表理解将为空。同样,如果uid uname 1 alex 2 anna 3 sergey 4 arnold 5 john mid message uid 1 hello 3 2 DELETED 3 3 xcvcxv 4 4 bye 1 5 DELETED 2 6 4452 5 为空,您将收到此错误。