我无法弄清楚为什么我的链表不起作用

时间:2010-12-13 00:16:01

标签: java

这就是我想要做的事情。

        linked n = stu;

        int d = datainput.readInt();
        for(int x = 0; x < d; x++){
            students student = new students();
            student.setlname(datainput.readUTF());
            student.setfname(datainput.readUTF());
            student.setAge(datainput.readShort());
            student.setSex(datainput.readChar());
            student.setRace(datainput.readChar());

            int coucounter = datainput.readInt();
            linked cou = student.getCou();
            for(int y = 0; y < coucounter; y++){
                System.out.print("WTF");
                courses course = new courses();
                course.setName(datainput.readUTF());
                course.setDept(datainput.readUTF());
                course.setHours(datainput.readShort());
                course.setGrade(datainput.readChar());
                cou.setObject(course);  //Something wrong here
                cou = cou.getNext();

            }
            n.setObject(student);
            n = n.getNext();

        }

编辑:这是我的链接课程

public class linked {
    private Object ob;
    private linked next;

    linked(){
    }

    void setNext(linked l){
        next = l;
    }

    void setObject(Object o){
        ob = o;
    }

    linked getNext(){
        return next;
    }

    Object getObject(){
        return ob;
    }
}

1 个答案:

答案 0 :(得分:-1)

找到它。

                cou.setObject(course);
                cou.setNext(new linked());
                cou = cou.getNext();

            n.setObject(student);
            n.setNext(new linked());
            n = n.getNext();

奇怪,因为我之前使用链接列表之前我不需要这样做,而且类完全一样。那好吧!现在就行! WOOT