0
public static void computePaths(Vertex source)
{
    source.minDistance = 0.;
    PriorityQueue<Vertex> vertexQueue = new PriorityQueue<Vertex>();
    vertexQueue.add(source);

    while (!vertexQueue.isEmpty())
    {
        Vertex u = vertexQueue.poll();

        ///////////////////////////////
        // This is where the error is happening
        ///////////////////////////////
        for (Edge e : u.adjacencies)
        {
            Vertex v = e.target;

            double weight = e.weight;
            double distanceThroughU = u.minDistance + weight;

            if (distanceThroughU < v.minDistance)
            {
                vertexQueue.remove(v);
                v.minDistance = distanceThroughU;

                v.previous = u;

                vertexQueue.add(v);
            }
        }
    }
}

I'm getting the Runtime Error

Exception in thread "main" java.lang.NullPointerException
at Dijkstra.computePaths(Solution.java:69)
at Solution.main(Solution.java:141)

The program works fine with hard-coded vertices and paths, however the problem is going to be tested through file input, so I'm assuming it has to do with when I am taking in those values, but I can't find anything that would cause that error.

below is from where I take in the values

for (int i = 0; i < plans; i++)
    {
        vs[i] = new Vertex(scan.next());
        destinations[i] = new Vertex(scan.next());
        weights[i] = scan.nextInt();
        scan.nextLine();
    }

    for (int i = 0; i < plans; i++)
    {
        vs[i].adjacencies = new Edge[]
        { new Edge(destinations[i], weights[i]) };

    }

    Vertex[] vertices = new Vertex[plans];

    for (int i = 0; i < plans; i++)
    {
        vertices[i] = vs[i];
    }

    // starting vertice
    String start = scan.next();
    // ending vertice
    String end = scan.next();

    Dijkstra.computePaths(vs[0]);

0 Answers0