I’m not sure why this isn’t working. Java isn’t giving me an error
I have this in my StateController class

public void insertLinks()
        for(int index=0; //index is a local variable for state objects
                index < numStates;
         //for loop to continue making state objects stopping at numStates(50)

This should work right?

My insertFirst code in my LinkList class is

public void insertFirst(States dd) 
    {                          // if insert at front of list.  NO SEARCH!!
        Link newLink = new Link(dd);   // make new link                                       
        if (isEmpty()) // if empty list,
            last = newLink;                      // Points to end of list
        } else {
            first.previous = newLink;    
            newLink.next = first;           //    Points to next link
        first = newLink;                  //Points to start of Linked List           
    }// end insertFirst()

Exception in thread "main" java.lang.NullPointerException
at project3mitchell.StateController.insertLinks(StateController.java:168)
at project3mitchell.Main.main(Main.java:25)

Those are the errors I am getting

Recommended Answers

maybe your 'myList' variable is not initialized properly?

Jump to Post

All 3 Replies

maybe your 'myList' variable is not initialized properly?

my friend just pointed that out to me and that's exactly what it was. Thank you for your help you were right on the money. I forgot to use LinkList myList = new LinkList(); That's where it screwed up. I forgot the new LinkList(); I tend to forget stupid things like that.

My pleasure. Mark this thread as solved if you don't have that problem anymore. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.