空指针异常
package com.hujinming.test;
public class Course {
public String id;
public String name;
public Course(String id , String name) {
this.id = id;
this.name = name;
System.out.println("执行了!");
}
}
package com.hujinming.test;
import java.util.ArrayList;
import java.util.List;
public class CourseToStudent {
public List courseToSelect;
public void CourseToStudent() {
this.courseToSelect = new ArrayList();
}
/**
*
* 用于往备选课程里面添加课程
*/
public void courseAdd() {
Course crl = new Course("1","高数");
courseToSelect.add(crl);//这儿出现空指针异常
Course temp = (Course) courseToSelect.get(0);
System.out.println("添加了课程"+":"+temp.id+","+temp.name);
}
}