Run time error is caused due to wrong handling of empty input list, when list is empty one need to return null but in the above program this case is not handled , and in the line 6 an attempt is made to access the next field of a null pointer which causes a NullPointerException
"So 3,4,4 means there are two nodes between node 3 and node 4."
I think you mean "there are two edges between node3 and node4"
in fact ,it make sense that allow more than one edge between nodes.
if each edge was tag with a value then it can be understood much easier