2

I currently have the following Node List: {3,2,5,6,2,5}

When I invoke: trailer.getPrev() the output is 2. The problem is I want to return 5, how do I do this.

I have tried: return trailer; but then I get an error: The trailer node is not a valid position

Thanks for any help.

EDIT: Its a NodePositionList

Soler Mani
  • 301
  • 3
  • 5
  • 15
  • Without knowing the classes and API you are using this is like asking us 'How long is this piece of string I'm holding here?'. – mcfinnigan Feb 27 '12 at 16:20

2 Answers2

1

If it's an implementation of NodeList, you should be able to access the last item with

yourList.item(yourList.getLength()-1);

EDIT:

With a NodePositionList, regarding the documentation, you should be able to do the same with something like:

yourList.checkPosition(yourList.last());

that will return a DNode. last() only returns the position of the last item in the list.

talnicolas
  • 13,885
  • 7
  • 36
  • 56
1

The error message links to various custom node list implementations. From looking at that code, you might see a method last() on the node list class. Do something like nodelist.last() to get the last list element.

It will call trailer.getPrev() internally, and if it works, then your trailer does not point to the real trailer position.

Andreas Dolk
  • 113,398
  • 19
  • 180
  • 268
  • 7? I don't see a 7 in your list!? We **need** to see the relavant code and we need the (fully qualified) name of your node list class. – Andreas Dolk Feb 27 '12 at 20:28