我正在尝试在java中使用嵌入式neo4j在neo4j中插入节点,但是我得到了这个错误,我正在使用neo4j 3.1.1和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)
我不知道变量DB_PATH = "D:\\Neo4j CE 3.1.1\\graph database"
中是否存在问题
应该包含变量DB_PATH
应该是什么?
代码是:
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);
}
}
答案 0 :(得分:0)
我基本上有同样的问题;它是由于CLASSPATH中存在较旧版本的Neo4J以及我试图使用的新版本引起的。 (我在学习新IDE时不会清除旧目标的过程中学到了这一点,这就是旧版本存在的原因。)
确保您刷新了相关.jars的所有旧版本。