Menu

#78 Possible error in JUNG Manual code

open
nobody
None
5
2007-06-26
2007-06-26
Anonymous
No

Hello,

From this page, http://jung.sourceforge.net/doc/manual.html#gve i tried running this segmant of code:

Graph original = new DirectedSparseGraph();
Vertex v1_orig = original.addVertex(new DirectedSparseVertex());
Vertex v2_orig = original.addVertex(new DirectedSparseVertex());
DirectedEdge e_orig = original.addEdge(new DirectedSparseEdge(v1, v2));

Graph target = new DirectedSparseGraph();
Vertex v1_copy = v1_orig.copy(target);
Vertex v2_copy = v2_orig.copy(target);
DirectedEdge e_copy = e_orig.copy(target);

However, when i ran that, i got this error:

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Type mismatch: cannot convert from Edge to DirectedEdge
v1 cannot be resolved
v2 cannot be resolved
Type mismatch: cannot convert from ArchetypeVertex to Vertex
Type mismatch: cannot convert from ArchetypeVertex to Vertex
Type mismatch: cannot convert from ArchetypeEdge to DirectedEdge

at SimpleGraphDraw2.main(SimpleGraphDraw2.java:47)

(I am using eclipse).

However, changing the code to this:

Graph original = new DirectedSparseGraph();
Vertex v1_orig = original.addVertex(new DirectedSparseVertex());
Vertex v2_orig = original.addVertex(new DirectedSparseVertex());
DirectedSparseEdge e_orig = new DirectedSparseEdge(v1_orig, v2_orig);
original.addEdge(e_orig);

Graph target = new DirectedSparseGraph();
Vertex v1_copy = (Vertex)v1_orig.copy(target);
Vertex v2_copy = (Vertex)v2_orig.copy(target);
DirectedSparseEdge e_copy = new DirectedSparseEdge(v1_copy, v2_copy);
target.addEdge(e_copy);

resulted in the program executing properly.

Hope this helps.

Alex
primalfear@comcast.net

Discussion


Log in to post a comment.