为什么编译出错啊?这是什么错误啊?
package gg;
public class Course {
public String id;
public String name;
public Course(String id,String name)
{
this.id=id;
this.name=name;
}
}
package gg;
import java.util.HashSet;
import java.util.Set;
public class Student {
public String id;
public String name;
public Set courses;
public void Student(String id,String name)
{
this.id=id;
this.name=name;
this.courses=new HashSet();
}
}
package gg;
import java.util.ArrayList;
import java.util.List;
public class ListTest {
public List coursestoselect;
public void Listest()
{
this.coursestoselect=new ArrayList();
}
public void testAdd()
{
Course c1=new Course("1", "数学");
coursestoselect.add(c1);
Course temp=(Course)coursestoselect.get(0);
System.out.println("添加课程:"+temp.id+","+temp.name);
}
public static void main(String[] args) {
ListTest lt=new ListTest();
lt.testAdd();
}
}
为什么编译出错啊?
Exception in thread "main" java.lang.NullPointerException
at gg.ListTest.testAdd(ListTest.java:16)
at gg.ListTest.main(ListTest.java:24)
这是什么错误啊?