package com.imooc;
import java.util.ArrayList;
import java.util.List;
public class TestGeneric {
public List<Course> courses;
public void TestGeneric(){
this.courses=new ArrayList<Course>();
}
public void testAdd(){
Course cr=new Course("1","English");
courses.add(cr);
Course cr1=new Course("2","Chinese");
courses.add(cr1);
}
/**
*
*/
public void testForEach(){
for(Course cr:courses){
System.out.println("课程:"+cr.id+":"+cr.name);
}
}
public static void main(String[] args) {
TestGeneric te=new TestGeneric();
te.testAdd();
te.testForEach();
}
}
报错提示:Exception in thread "main" java.lang.NullPointerException
at com.imooc.TestGeneric.testAdd(TestGeneric.java:13)
at com.imooc.TestGeneric.main(TestGeneric.java:27)
leeu
冰山点水
随时随地看视频慕课网APP
相关分类