The method below is basic insight of what I am planning to output: the account part works but when I try to print along with the transactions I get the nullpointer exception. The reason is I am using my own queue implementation, underneath the method is my iterator so far but I have no clue what I am missing for this to not work? public void Display_Account() { System.out.println("Student ID: " + Student_ID); System.out.println("Student Name: " + Student_Name); System.out.println("Student Email: " + Student_Email); System.out.println("Creation Date (DD/MM/YYYY): " + Creation_Date); System.out.println("Credit: " + Credit_Balance); System.out.println("*----------------------*"); // Code indicates not applicable to expression type and requires iterable to be implemented for (Student_Transaction Tr : Transaction) { Tr.Display_Transaction(); } } Therefore, I will need to implement the Iterator in my queue class which is the data structure I am using to add or remove objects, despite I'm missing few errors but I dont know where. // Queue uses class List. import java.util.Iterator; public class Queue <t> implements Iterable <t> { private List<t> queueList; private int capacity; // no-argument constructor public Queue() { queueList = new List<>("queue"); capacity = 1; } // end Queue no-argument constructor @Override public Iterator<t> iterator() { return null; } class QueueIt implements Iterator<t> { // Where the iterator problem is in particular! public class QueueIt implements Iterator<t> { @Override public boolean hasNext() { return false; } @Override public T next() { return null; } } // add object to queue public void enqueue(T object) { queueList.insertAtBack(object); capacity++; } // end method enqueue // remove object from queue public T dequeue() throws EmptyListException { return queueList.removeFromFront(); } // end method dequeue public void Decrement() { capacity--; } public int Size() { return capacity; } // determine if queue is empty public boolean isEmpty() { return queueList.isEmpty(); } // end method isEmpty // output queue contents public void print() { queueList.print(); } // end method print } What I have tried: Every example I have found are related to LinkedList. Dont get me wrong Queue is a member of LinkedList and the bigger picture (Collections utility and iterator). But I am not sure what I am missing out that my Code wont Iterate through objects. P.S If you need to see my List class just say so and I will edit the Snippet above.
next()
null
hasNext()
false
hasNext
next
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)