CoursesToSelect.add(cr1); Course temp = CoursesToSelect.get(0); 報錯了
下面是包的錯誤 朋友們幫我看看
Exception in thread "main" java.lang.Error: Unresolved compilation problems:?
CoursesToSelect cannot be resolved
CoursesToSelect cannot be resolved
at com.imooc.cellection.ListTest.testAdd(ListTest.java:18)
at com.imooc.cellection.ListTest.main(ListTest.java:24)
2016-09-17
package?com.imooc.collection; import?java.util.ArrayList; import?java.util.List; //備選課程類 public?class?ListTest1?{ /** *?用于存放備選課程的list */ public?List?coursesToSelect; public?ListTest1(){ this.coursesToSelect?=?new?ArrayList(); } /** *?用于往coursesToSelect中添加備選課程 */ public?void?testAdd(){ Course?cr1?=?new?Course("1","數(shù)據(jù)結(jié)構(gòu)"); coursesToSelect.add(cr1); Course?temp?=?(Course)?coursesToSelect.get(0); System.out.println("添加課程:"+temp.getId()?+":"+temp.getName()); } public?static?void?main(String[]?args)?{ ListTest?it?=?new?ListTest(); it.addTest(); } }我?guī)湍愀倪^來了,自己看看吧
2016-09-14
package com.imooc.cellection;
import java.util.ArrayList;
import java.util.List;
//備選課程類
public class ListTest {
/**
* 用于存放備選課程的list
*/
public List coursesToSelect;
public ListTest(){
this.coursesToSelect = new ArrayList();
}
/**
* 用于往coursesToSelect中添加備選課程
*/
public void testAdd(){
Course cr1 = new Course("1","數(shù)據(jù)結(jié)構(gòu)");
CoursesToSelect.add(cr1);
Course temp = CoursesToSelect.get(0);
System.out.println("添加課程:"+temp.id +":"+temp.name);
}
public static void main(String[] args) {
ListTest it = new ListTest();
it.testAdd();
}
}
這是源碼