i am trying to add nodes to a list (similiar to a linkedlist) but i keep getting errors at my add method and where i call the add method in my main.
public class LLList<T> { private Node firstNode; // reference to first node private int length; // number of entries in list public LLList(){ clear(); } public final void clear() { firstNode = null; length = 0; } public boolean add(T newEntry) { Node newNode = new Node(newEntry);//getting the error here if (isEmpty()){ firstNode = newNode; }else{ Node lastNode = getNodeAt(length); lastNode.next = newNode; // make last node reference new node } length++; return true; } public void display() { Node currentNode = firstNode; while(currentNode != null){ System.out.println(currentNode.data); currentNode = currentNode.next; } } public boolean isEmpty() { boolean result; if (length == 0){ assert firstNode == null : "length = 0 but firstNode is not null"; result = true; }else{ assert firstNode != null : "length not 0 but firstNode is null"; result = false; } return result; } /** Task: Returns a reference to the node at a given position. * Precondition: List is not empty; 1 <= givenPosition <= length. * @param givenPosition * @return */ private Node getNodeAt(int givenPosition){ assert (!isEmpty() && 1 <= givenPosition && givenPosition <= length); Node currentNode = firstNode; for (int counter = 1; counter < givenPosition; counter++){ currentNode = currentNode.next; } assert currentNode != null; return currentNode; } private class Node //private inner class { private T data; private Node next; private Node(T dataPortion){ data = dataPortion; next = null; } private Node(T dataPortion, Node nextNode){ data = dataPortion; next = nextNode; } }// end Node public static void main(String[] args) { LLList<String> list = new LLList<String>(); list.add("bobby");//getting the error here list.add("joey"); list.display(); } }
this is the error i see when i try to compile:
Exception in thread "main" java.lang.ClassFormatError: Duplicate method name&signature in class file LLList$Node
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknow n Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at LLList.add(LLList.java:18)
at LLList.main(LLList.java:84)
your help would be appreciated. thank you!