I am getting started with Java Universal Network/Graph Framework (JUNG). I am trying to build a basic graph using the same. I downloaded the jung 2.0.1 libraries. collections-generic-4.0.1.jar and colt-1.2.0.jar. I added all the included libraries to my eclipse project build path. But I am getting the following exception whenever i am trying to run...
package grapheditor;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.graph.SparseMultigraph;
import edu.uci.ics.jung.graph.util.EdgeType;
/**
* The simplest JUNG2 graph creation example possible?
* Shows how easy the new JUNG2 graph interface and implementation class is
* to use.
* @author Dr. Greg M. Bernstein
*/
public class SimplestGraph {
public static void main(String[] args) {
// Graph<V, E> where V is the type of the vertices and E is the type of the edges
SparseMultigraph<Integer, String> g = new SparseMultigraph<Integer, String>();
// Add some vertices. From above we defined these to be type Integer.
g.addVertex((Integer)1);
g.addVertex((Integer)2);
g.addVertex((Integer)3);
// Add some edges. From above we defined these to be of type String
// Note that the default is for undirected edges.
g.addEdge("Edge-A", 1, 2); // Note that Java 1.5 auto-boxes primitives
g.addEdge("Edge-B", 2, 3);
// Let's see what we have. Note the nice output from the SparseMultigraph<V,E> toString() method
System.out.println("The graph g = " + g.toString());
// Note that we can use the same nodes and edges in two different graphs.
SparseMultigraph<Integer, String> g2 = new SparseMultigraph<Integer, String>();
g2.addVertex((Integer)1);
g2.addVertex((Integer)2);
g2.addVertex((Integer)3);
g2.addEdge("Edge-A", 1,3);
g2.addEdge("Edge-B", 2,3, EdgeType.DIRECTED);
g2.addEdge("Edge-C", 3, 2, EdgeType.DIRECTED);
g2.addEdge("Edge-P", 2,3); // A parallel edge
System.out.println("The graph g2 = " + g2.toString());
}
}
i am getting the following exception:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections/Predicate
at grapheditor.SimplestGraph.main(SimplestGraph.java:17)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.collections.Predicate
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
It made me thinking that the collections-generic-4.0.1.jar is causing it. So i extracted it and found that the package structure in it is org/apache/commons/collections15/Predicate instead of org/apache/commons/collections/Predicate. Is this causing the problem? Any help in this light will be appreciated...
Write this in your code to specify where you want the Predicate class from:
import org.apache.commons.collections15.Predicate
or if you may need some other classes inside the package:
import org.apache.commons.collections15.*
Also, you can extract the .jar file and create a new one with the correct path to your Predicate
class.