arraylist - array list error in dijkstra algoritim java -
i want utilize dijkstra algorithm info database here past of code:
list ed = new arraylist(); while(rscost.next()) { int cost = integer.parseint(rscost.getstring(3)); vertex v2= hst.get(rscost.getstring(1));// vertex hastable ed.add(new edge(v2,cost)); } v1.adjacencies= new edge[]{ed};
v1 vertex , main object creating object:
v1.adjacencies = new edge[]{ new edge(v0, 5), new edge(v2, 3), new edge(v4, 7) };
like in examples.
it throws type mismatch: cannot convert list edge.
.
if cast ed border throws null
value.
what should add together elements?
given adjacencies
array of edges, can populate adjacencies
objects of type edge
.
v1.adjacencies= new edge[]{ed};
this line trying populate adjacencies
list object, not border object. since variable ed
cannot cast list edge, getting type mismatch error.
instead, need take list , convert array of edges. or can create adjacencies list object instead of array.
java arraylist dijkstra
No comments:
Post a Comment