Skip to content
Advertisement

Doubly Linked List adding null

I’m new to Java. I want to make student information system, but whenever I used the addStudent method, I get a list with null values.

This is the student class for getting names telephone numbers and student ID.

JavaScript

This is the Node class. Methods can be wrong maybe they are too complicated sorry for that. I’m trying to learn Java.

JavaScript

And this is the DoublyLinkedList. I think my main problem is here, but I didn’t figure out how I can solve this, so any help is appreciated.

JavaScript
JavaScript

Advertisement

Answer

Your “display” function only prints the “line” member of the nodes irrespective of whether you set the “line” member or not. And your “liste2” variable is populated with “Student” instances and not “String”s. Which means that only the “student” member of the node will be set and the “line” member will be left “null”. Hence printing the second list, you will only see nulls, since the “line” members are never set for the nodes.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement