0

I am new to the jung library, and I am trying to create a new vertex and am following the jung tutorial carefully (here: http://jung.sourceforge.net/doc/manual.html#start). But, I my eclipse IDE cannot recognize the DirectedSparseVertex class or the DirectedEdge class when I try to use it. I am wondering if I am missing the import or something? But here is my code. Hope you guys can help.

    import java.net.URL;
    import java.util.ArrayDeque;
    import java.util.ArrayList;
    import java.util.LinkedList;
    import java.util.PriorityQueue;
    import java.util.Queue;

    import org.jgrapht.DirectedGraph;
    import org.jgrapht.graph.DefaultEdge;
    import edu.uci.ics.jung.graph.DirectedSparseGraph;
    import edu.uci.ics.jung.graph.Graph;
    import edu.uci.ics.jung.graph.SparseGraph;
    import edu.uci.ics.jung.visualization.renderers.Renderer.Vertex;


    public class LockNodes 
    {
        public LockNodes()
        {
            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);
        }
    }

So its underlying in red: new DirectedSparseVertex() and DirectedEdge e_copy

Dr.Android
  • 259
  • 1
  • 8
  • 22

1 Answers1

1

The classes you're referencing (DirectedSparseVertex and DirectedEdge) are from JUNG 1.x; you are presumably using the new JUNG 2.x classes, which don't have types for vertices and edges.

(Note, by the way, that the new home for JUNG, as of v2.1, is on GitHub: http://jrtom.github.io/jung/)

I suggest that you take a look at the current Javadoc and samples, documented here: http://jrtom.github.io/jung/javadoc/index.html

and at this tutorial (a bit out of date, but based on v2): http://www.grotto-networking.com/JUNG/JUNG2-Tutorial.pdf

Joshua O'Madadhain
  • 2,704
  • 1
  • 14
  • 18
  • Thanks! Is there a jar file anywhere with for this library, how do i import this library into eclipse? – Dr.Android Jul 13 '16 at 04:36
  • The zipped jar files are available on GitHub, at the first link in my answer. For dealing with JUNG and Eclipse, here's this answer: http://stackoverflow.com/questions/5616233/how-do-i-install-jung2-on-eclipse – Joshua O'Madadhain Jul 13 '16 at 05:06
  • Thanks for the link sir. – Dr.Android Jul 13 '16 at 05:47
  • So I followed the link you sent me but I got an NoClassDefFoundError when I tried to use the class "Graph". Here is the link to the jar files I downloaded and used: https://github.com/jrtom/jung/blob/master/README.md . I downloaded these jars. Then in eclipse, in my source folder, i right clicked and went to properties, then to libraries and then "add external jars" and added those files. It imported correctly, but when I run it. I get that error??? – Dr.Android Jul 13 '16 at 07:17
  • I can't really remotely debug your Eclipse setup, sorry. I suggest finding an Eclipse forum (maybe there's one on StackOverflow) and asking this as a separate question, or trying a web search on "Eclipse NoClassDefFoundError". Good luck. – Joshua O'Madadhain Jul 13 '16 at 17:12