From f3a1f51d10d1a6e38cedc38315c952b7eb309833 Mon Sep 17 00:00:00 2001 From: Antonin Godard Date: Wed, 3 Jan 2018 10:35:09 +0100 Subject: [PATCH] Fix shortestPath NullPointerException Fix exception when the departure and the arrival are next to each other. I redefined the path by including the arrival in the path. --- src/dijkstra/Previous.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/dijkstra/Previous.java b/src/dijkstra/Previous.java index 15f2280..461263a 100644 --- a/src/dijkstra/Previous.java +++ b/src/dijkstra/Previous.java @@ -28,12 +28,14 @@ public class Previous implements PreviousInterface { } public ArrayList getShortestPathTo(VertexInterface vertex) { - + + shortestPath.add(vertex); VertexInterface father = getPrevious(vertex) ; - shortestPath.add(father) ; - if (((Box) getPrevious(father)).isDeparture()) return shortestPath ; - else { + if (((Box) getPrevious(father)) == null) { + shortestPath.add(father); + return shortestPath ; + } else { return getShortestPathTo(father) ; } }