慕移动0989271
2017-05-05 13:19
public void testGet() {
int size = coursesToSelect.size();
System.out.println("有如下课程待选:");
for(int i= 0 ; i < size; i++) {
Course cr=(Course)coursesToSelect.get(i);
System.out.println("课程:" + cr.id + ":" + cr.name);
}
}
private void testForEach() {
System.out.println("有如下课程待选(通过for each访问):");
Course course=new Course();
for (Object obj : coursesToSelect) {
Course cr =(Course) obj;
System.out.println("课程:" + cr.id + ":" + cr.name);
Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to com.imooc.collection.Course
at com.imooc.collection.ListTest.testGet(ListTest.java:127)
at com.imooc.collection.ListTest.main(ListTest.java:118)
就是他导致的异常
找到了
public static void main( String[] args) {
ListTest lt = new ListTest();
lt.testAdd();
// lt.testType();
lt.testForEach();
lt.testGet();
lt.testIterator();
lt.testForEach();
lt.testModify();
lt.testForEach();
lt.testRemove();
}
把上面的testtype也注释了
Java入门第三季
409792 学习 · 4340 问题
相似问题