添加addAll方法时候,为什么报空指针异常? 求 高人解答
public class TestGeneric {
/**
* 首先创建一个集合并泛型
* @param args
*/
public List<Course> courses;
/**
* 添加方法
* @param args
*/
public void testAdd(){
Course[] course1 = {new Course("1","大学英语"),
new Course("2","高等数学")};
courses.addAll(Arrays.asList(course1));
for(Course cr: course1){
System.out.println(cr.getId() + ":" + cr.getName());
}
}
public static void main(String[] args) {
TestGeneric tg= new TestGeneric();
tg.testAdd();
}
}