问答详情
源自:4-4 学生选课---添加课程 Ⅰ

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)


提问者:qq_冲_0 2016-09-14 20:42

个回答

  • 你已走远
    2016-09-17 09:11:11
    已采纳

    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","数据结构");
    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();
    }
    
    }

    我帮你改过来了,自己看看吧

  • qq_冲_0
    2016-09-14 20:45:07

    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","数据结构");

    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();

    }


    }

    这是源码