How can I resolve java.lang.NoSuchMethodError: org.neo4j.helpers.collection.Iterables.toList(Ljava/lang/Iterable;)Ljava/util/List?

家住魔仙堡 提交于 2019-12-11 08:30:52

问题


I'm trying insert nodes in neo4j using embedded neo4j in java, but I obtain this error, i'm using neo4j 3.1.1 and netbeans 7

Exception in thread "main" java.lang.NoSuchMethodError: org.neo4j.helpers.collection.Iterables.toList(Ljava/lang/Iterable;)Ljava/util/List;
    at org.neo4j.graphdb.factory.GraphDatabaseFactory.<init>(GraphDatabaseFactory.java:49)
    at twitter4j.EmbeddeNeo4j.createDb(EmbeddeNeo4j.java:41)

I don't know if the problem in variable DB_PATH = "D:\\Neo4j CE 3.1.1\\graph database" what should the variable DB_PATH be contained? the code is :

void createDb() {
        clearDb();
        // start DB
        graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
        registerShutdownHook(graphDb);

        // start Transaction
        Transaction tx = graphDb.beginTx();
        try {
            // adding data
            firstNode = graphDb.createNode();
            firstNode.setProperty("message", "Hello, ");
            secondNode = graphDb.createNode();
            secondNode.setProperty("message", "World!");

            relationship = firstNode.createRelationshipTo(secondNode, RelTypes.KNOWS);
            relationship.setProperty("message", "brave Neo4j ");

            // reading data
            System.out.println(firstNode.getProperty("message"));
            System.out.println(relationship.getProperty("message"));
            System.out.println(secondNode.getProperty("message"));

            greeting = (String) firstNode.getProperty("message") + (String) relationship.getProperty("message") + (String) secondNode.getProperty("message");

            Iterator<Relationship> it = firstNode.getRelationships().iterator();
            while(it.hasNext()) {
                Relationship r = it.next();
                Node[] nodes = r.getNodes();
                System.out.println(nodes[0].getProperty("message") + " " + r.getProperty("message") + " " + nodes[1].getProperty("message"));
            }

            tx.success();
        } finally {
            tx.terminate();
        }

    }

private void clearDb() {
    try {
        FileUtils.deleteRecursively(new File(DB_PATH));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

回答1:


I had essentially this same problem; it was caused by the presence of older versions of Neo4J in the CLASSPATH along with the new one I was trying to use. (I learned along the way that my IDE doesn't clean out old targets before building new ones, which is why the older versions were there.)

Make sure that you've flushed out all older versions of the relevant .jars.



来源:https://stackoverflow.com/questions/43203502/how-can-i-resolve-java-lang-nosuchmethoderror-org-neo4j-helpers-collection-iter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!