Nurgul Alshyn
Nurgul Alshyn

Reputation: 79

listIterator not working

I keep getting an error: The method listIterator() is undefined for the type Salama.

Is it because Salama is not a LinkedList?

Here's the code in 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); 

Here's from the class:

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

Upvotes: 1

Views: 1683

Answers (1)

deyur
deyur

Reputation: 567

Your Salama class needs a listIterator method (if you want to use a list iterator). Based on your usage the signature should look like

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

It may be worth reading up on the standard ListIterator docs: http://docs.oracle.com/javase/7/docs/api/java/util/ListIterator.html

Upvotes: 1

Related Questions