【问题标题】:JUNG Exception in "main" :org/apache/commons/collections/Predicate“main”中的 JUNG 异常:org/apache/commons/collections/Predicate
【发布时间】:2013-05-21 11:55:07
【问题描述】:

我开始使用 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。这是造成问题的原因吗?在这方面的任何帮助将不胜感激......

【问题讨论】:

    标签: java eclipse noclassdeffounderror jung generic-collections


    【解决方案1】:

    在你的代码中写下这个来指定你想要 Predicate 类的来源:

    import org.apache.commons.collections15.Predicate
    

    或者如果您可能需要包内的其他类:

    import org.apache.commons.collections15.*
    

    此外,您可以提取 .jar 文件并创建一个新的文件,其中包含指向您的 Predicate 类的正确路径。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-03
      • 1970-01-01
      • 1970-01-01
      • 2020-11-15
      • 1970-01-01
      • 2013-03-19
      • 2017-08-13
      相关资源
      最近更新 更多