this is my first attempt to a code doubly linked program in java:
This is my implementation of getting an iterator to getall items in the doubly linkedlist
public Object next() {
if(list.getSize()==0){
throw new NoSuchElementException();
}else{
current=current.getNext();
return current.getItem();
}
}
Please dont laugh at me but whatever I try I am getting
Cannot find symbol : symbol class: NoSuchElementException
I tried creating a class NoSuchElementException.java which extends Exception
Then I get
unreported exception NoSuchElementException; must be caught or
declared to be thrown
throw new NoSuchElementException();
I tried changing code to :
public Object next() throws NoSuchElementException {
Then I get
next() in ElementsIterator cannot implement next() in
java.util.Iterator; overridden method does not throw
NoSuchElementException
Can anybody point to where I got wrong. If this is not sufficient info to resolve this issue, please do tell me.
You need to import
java.util.NoSuchElementExceptioninstead of creating your own.