原帖
让我从我的代码开始。这是出现错误的代码片段。
DatabaseModuleInterface dbModule = new DatabaseModuleImpl();
System.out.println(dbModule.getDb());
Traverser t = dbModule.getGraphTree(usernode);
System.out.println("DBMODULE = " + dbModule.toString());
System.out.println("USERNODE = " + usernode);
System.out.println("TRAVERSER1 = " + dbModule.getGraphTree(usernode));
System.out.println("T IS NOT NULL");
if (t.nodes() != null) {
System.out.println("T NODES IS NOT NULL");
for (Node node : t.nodes()) {
if (node != null) {
System.out.println("NODE IS NOT NULL");
} else {
System.out.println("NODE IS NULL");
}
}
}
哪个返回
INFO: EmbeddedGraphDatabase [C:\impactordb]
INFO: DBMODULE = be.archimiddle.impactor.modules.database.interfaces.DatabaseModuleImpl@bed5ea
INFO: USERNODE = Node[241]
INFO: TRAVERSER1 = org.neo4j.kernel.impl.traversal.TraverserImpl@ce2016
INFO: T IS NOT NULL
INFO: T NODES IS NOT NULL
然后出现以下堆栈跟踪的错误
java.lang.NullPointerException
at org.neo4j.kernel.impl.nioneo.xa.ReadTransaction.nodeLoadLight(ReadTransaction.java:86)
at org.neo4j.kernel.impl.persistence.PersistenceManager.loadLightNode(PersistenceManager.java:82)
at org.neo4j.kernel.impl.core.NodeManager.getLightNode(NodeManager.java:423)
at org.neo4j.kernel.impl.core.NodeManager.getNodeForProxy(NodeManager.java:440)
at org.neo4j.kernel.InternalAbstractGraphDatabase$4.lookup(InternalAbstractGraphDatabase.java:660)
at org.neo4j.kernel.impl.core.NodeProxy.getRelationships(NodeProxy.java:98)
at org.neo4j.kernel.StandardExpander$RegularExpander.doExpand(StandardExpander.java:579)
at org.neo4j.kernel.StandardExpander$RelationshipExpansion.iterator(StandardExpander.java:194)
at org.neo4j.kernel.impl.traversal.TraversalBranchWithState.expandRelationshipsWithoutChecks(TraversalBranchWithState.java:78)
at org.neo4j.kernel.impl.traversal.TraversalBranchImpl.expandRelationships(TraversalBranchImpl.java:104)
at org.neo4j.kernel.impl.traversal.StartNodeTraversalBranch.next(StartNodeTraversalBranch.java:46)
at org.neo4j.kernel.impl.traversal.AsOneStartBranch.next(AsOneStartBranch.java:100)
at org.neo4j.kernel.PreorderDepthFirstSelector.next(PreorderDepthFirstSelector.java:52)
at org.neo4j.kernel.impl.traversal.TraverserIterator.fetchNextOrNull(TraverserIterator.java:64)
at org.neo4j.kernel.impl.traversal.TraverserIterator.fetchNextOrNull(TraverserIterator.java:33)
at org.neo4j.helpers.collection.PrefetchingIterator.hasNext(PrefetchingIterator.java:55)
at org.neo4j.helpers.collection.IteratorWrapper.hasNext(IteratorWrapper.java:42)
at com.archimiddle.impactor.action.navigation.ViewGraphAction.getGraphTree(ViewGraphAction.java:107)
此行 #107 是代码段中的以下行:
for(Node node : t.nodes()){
我检查了所有内容的空值,但找不到任何东西。如果有人可以帮助我,将不胜感激。
编辑
我使用这种方法来显示隐藏在我的图表中的树。我知道该方法有效,因为我可以看到我的图表。
只是在我使用 tinkerpop 蓝图中的 Neo4jgraph 添加节点后,我不再可以使用该方法查看我的图。为了让 Gremlin 将节点实际添加到我的 Neo4J 图中,我必须在提交节点之前调用关闭或 stopTransaction。
Neo4jgraph graph = new Neo4jGraph(my_graphdatabaseservice);
//ADD NODES HERE
//I USED TO DO THIS
neo4jgraph.shutdown();
//NOW I DO THIS
neo4jgraph.stopTransaction(Conclusion.SUCCESS);
我必须做这两个中的一个,否则我的节点将不会被提交。出于一个非常具体的原因,我必须使用蓝图添加它们。
我怀疑它与此有关,因为它只发生在我这样做之后......