Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: From List<String> to a generic LinkedList

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: From List<String> to a generic LinkedList

    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.

  3. #3
    Junior Member
    Join Date
    Jul 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

Similar Threads

  1. Searching for string values in a circular list
    By hippo1974 in forum Object Oriented Programming
    Replies: 10
    Last Post: July 11th, 2011, 04:36 AM
  2. Generic Doubly Linked List
    By javapenguin in forum What's Wrong With My Code?
    Replies: 23
    Last Post: October 23rd, 2010, 03:13 PM
  3. LinkedList Objects
    By thedolphin13 in forum What's Wrong With My Code?
    Replies: 11
    Last Post: October 13th, 2010, 03:14 PM
  4. store a list/string for each object
    By tommy in forum Object Oriented Programming
    Replies: 5
    Last Post: May 28th, 2010, 09:24 AM
  5. String substring, concatenation operation on linked list
    By oaks12 in forum Collections and Generics
    Replies: 1
    Last Post: January 15th, 2009, 07:12 AM