java - Checking for Null goes into infinite loop -


i've got data structure follows:

[object] -> [object] -> [objects]

each object has right pointer one.

while (currentparcel.getright() != null) {     currentparcel = currentparcel.getright(); } 

this code goes infinite loop.

by logic should go right as can, , when reached null, currentparcel object should last object pointer null (has no object right).

how can tackle infinite looping?

i've tried writing in following way:

boolean found = false; try {    while (found == false) {        currentparcel = currentparcel.getright();         if (currentparcel.getright() == null)        {            currentparcel.addright(p);            system.out.println(currentparcel);            found = true;        }      } }  catch (nullpointerexception e) {} 

but did not work me. not go far right can.

you've got circular link in linked list structure. debug this, either use debugger or println objects in while loop see are. way find problem. make sure objects have decent tostring() method , print them out inside of loop 1 way identify circular connection. also, don't have have "the last points first" occur, rather need circular connection exist somewhere. you'd best find it.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -