From List<String> to a generic LinkedList
Hi guys,
I was hoping someone can help me. I've been stuck on a problem for some time and I can't seem to find the solution.
My task is to take elements from a List<string> and put them into a generic linked list.
I've figured out how to use the listIterator and used that to cycle through all the names.
It works as long as I put in System.out.println(x); to the screen.
When I try to place the values into the LinkedList I get a never ending NullPointerException.
Here's the code if it helps:
//from main in a main source
List<String> words3 = Collections.unmodifiableList(names2);
aLinkedList wordlist = new LinkedList(names3);
System.out.println();
//from the linkedlist source
public aLinkedList(List<String> words){
ListIterator<String> itr = words.listIterator();
while (itr.hasNext()) {
String name = itr.next();
// System.out.println(words);
LLWords.add(words);
// for(String word : words) {
// System.out.println(words);
// }
}
I was trying different things and that's what the //'s were for. Thanks for any help.
-J
Re: From List<String> to a generic LinkedList
Quote:
I get a never ending NullPointerException.
Please copy and paste enough of the error message to identify what line it occurs on.
Look at that line of code and see which variable is null. Then back track to see why that variable is null.
Re: From List<String> to a generic LinkedList
I just resolved my own issue. The admin can delete my original post because it's not going to be helpful as it is now.
Thanks anyway.