solving while loop problem of getShortestPath, after loop 7 then will stuck