I'm having a problem implementing a linked list... It's contained in an object, and after instantiating the object, Highway h = new Highway(27.78,10000.0); The linked list inside it should be instantiated (I think), this is inside the constructor for Highway... LinkedList cars = new LinkedList(); The problem I'm having is that afterwars my linked list always appears to be null, even if I add something to it... and whever I try to use any of the methods of the linked list I get a Null Pointer Exception... If anybody's got any ideas, I'd appreciate some help, thanks.
your "cars" reference may be getting clobbered somewhere else in your code. Try looking for all references to "cars" and any assignments to it to make sure it isn't getting set to null. If you still have problems, try posting some code (try to post only relevant pieces though ...some folks will post 500 LOC and expect others to read through all of it :roll: ...NOT a thing to do here) HTH, Junilu
Kevin, Welcome to JavaRanch! My best guess is that you are declaring and instantiating a LinkedList inside your constructor only and as such this LinkedList doesn't exist outside of the constructor. Perhaps you could post some example code in the simplest form possible to replicate your problem. Good Luck.
I did some testing, and I can use the list inside the constructor, but anywhere else, it's null... so I'm pretty sure that backs up what you guys were saying.