java - null-pointer exception when coding bellmanFord algo -


In my computePaths () method I have an empty indicator exception, please help me find the reason below is my code And under my code I have output

Vertex class:

  applies square vertex Comparable & lt; Vertex & gt; {String name; Double minestration = double. POSITIVE_INFINITY; Vertex last; Edge [] adjacencies; Public string toasting () {return name; } Public Vertex (String Arrangement) {name = argName; } @ Override Compare Public Ent (Vertak Other) {Return Double Computer (Min Distant, Other Min Distance); }}  

Edge class:

  square edge {double weight; Vertex target; Public Edge (Vertex Aggregates, Double RRGite) {target = argTarget; Weight = argued; Class for algorithm:  
  Public class BellmanFord {public static zero computePaths (Vertex source, vertex [] corner) {source.minDistance = 0.0; PriorityQueue & LT; Vertex & gt; Vq = new priority question & lt; Vertex & gt; (); Vq.add (source); For (int i = 1; i & lt; vertices.length - 1; i ++) {while (! Vq.isEmpty ()) {Vertex u = vq.poll (); For (edge ​​e: u.adjacencies) {Vertex v = e.target; System.out.println (U + "+ e.target); double weight = e.wet; u through distance = u distances + weight; if (distance uuTt; v.minDistance) {vq.remove (v ); V.minDistance = distanceThroughU; V.previous = u; vq.add (v);}}}}} Public static list & gt; vertex & gt; GetShortestPathTo (vertex target) {list & lt; vertex & gt; Path = New Array List for (Vertex v = Target; v! = Null; v = v.previous) {path.add (v);} Collection; Reverse (path); Path to return;} Public static zero main (string [] r Vertex a = new vertex ("A"); vertex b = new vertex ("b"); vertex c = new vertex ("c"); vertex d = new vertex ("d"); vertex e = New Vertex ("e"); A.adjacencies = New Age [] (New Age (B, -1.0), New Age (C, 4.0)} B.adjacencies = New Age [] (New Age (D, 2.0 New Age (c, 3.0), New Age (E, 2.0)} D.adjacencies = New Age [] {New Age (B, 1.0)} E.adjacencies = New Age [] (New Age (D) , -3.0)}; vertex [] upper = {B, C, D, E}; compute path (A, cortis); (Vertex V: Cortes) {System.out.println ("+" v.toString ("+" is the distance for "+ v.minDistance"); System.out.println ("Path is" + Receive Taste Pathto (V));}}}  

And here is my output

  ABACBDBCBEDBEDDB exception in the thread "main" java.lang.NullPointerException BellmanFord.computePaths BellmanFord.java: 50) BellmanFord.main on (BellmanFord.java:106)  

This is a line 50 for (edge ​​e.adjacencies) and Line 106 is computepoint (a, cortes);

NPE should be thrown because you In the contiguity the c vertex reference has not been started but, you shorts with the computePaths method as the c.adjacencies as entered )


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -