listIterator不工作

时间:2014-10-01 23:30:54

标签: java listiterator

我一直收到错误:方法listIterator()未定义为Salama类型。

是因为Salama不是LinkedList吗?

这是main中的代码:

private Salama asteroids = new Salama();
private Salama rockets = new Salama(); 
private Station station = new Station (FrameWidth/2, FrameHeight-20); 

public void paint (Graphics g) { 
    station.paint(g); 

    ListIterator <Faeton> aIt = asteroids.listIterator();
    while (aIt.hasNext()) {
        Faeton asteroid = (Faeton) aIt.next();
        asteroid.paint(g); 

这是来自班级:

class Salama {     
    private Object data;  
    private Salama next;     
    private Salama head;

    Salama (){
        head = new Salama();
        head.setNext(null);
       }

    public void setNext(Salama e) {
    public Salama getNext()
    public void setData(Object d)

    public void add (Object o){
        Salama temp = new Salama();
        temp.setData(o);
        Salama current = head;
        while (current.getNext() != null){
            current = current.getNext();
        }
        current.setNext(temp);
    }
}

1 个答案:

答案 0 :(得分:1)

您的Salama类需要listIterator方法(如果您想使用列表迭代器)。根据您的使用情况,签名应如下所示

public ListIterator<Faeton> listIterator() {
    // Create a list iterator and return here.
}

可能值得阅读标准ListIterator文档:http://docs.oracle.com/javase/7/docs/api/java/util/ListIterator.html