通過迭代器出錯?
public void testIterator() {
??//通過集合的iterator方法,取得迭代器的事例
??
?? Iterator it = (Iterator) coursesToSelect.iterator();
?? System.out.println("有如下課程待選(通過迭代器訪問):");
?? while(it.hasNext()) {
??? Course cr =(Course)it.next();
??? System.out.println("課程:" + cr.id+ ":" + cr.name);
?? }
? }
?
?
2018-10-16
引入的包錯了,iterator在多個包中都有時實現(xiàn),你引入的是HTMLDocument.Iterator,正確的應(yīng)該是:java.util.Iterator
2018-09-09
報錯
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
?The method hasNext() is undefined for the type HTMLDocument.Iterator
?Type mismatch: cannot convert from void to Course
?at com.imooc_collection.ListTest.testIterator(ListTest.java:90)
?at com.imooc_collection.ListTest.main(ListTest.java:113)