此函数给出了不可预知的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
答案 0 :(得分:4)
StopIteration
将由next
引发,如果它被赋予空迭代。
如果dimensions
中的任何dim_list
与dim_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
为空,您将收到此错误。