我开始使用 Java 通用网络/图形框架 (JUNG)。我正在尝试使用相同的方法构建一个基本图表。我下载了 jung 2.0.1 库。集合通用 4.0.1.jar 和 colt-1.2.0.jar。我将所有包含的库添加到我的 Eclipse 项目构建路径中。但是每当我尝试运行时,我都会遇到以下异常...
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());
}
}
我收到以下异常:
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
这让我觉得是 collections-generic-4.0.1.jar 造成的。于是我把它提取出来,发现里面的包结构是org/apache/commons/collections15/Predicate,而不是org/apache/commons/collections/Predicate。这是造成问题的原因吗?在这方面的任何帮助将不胜感激......