2015-07-22 26 views
0

我的代碼如下,按照文件應該給我的節點值,但它拋出異常我發行鑄造節點的Neo4j

Exception in thread "main" java.lang.ClassCastException: scala.collection.convert.Wrappers$SeqWrapper cannot be cast to org.neo4j.graphdb.Node 
 
\t at com.neo4j.performance.FetchData.main(FetchData.java:32)
我使用的Neo4j 2.2.2。

import org.neo4j.graphdb.Node; 
import org.neo4j.graphdb.Result; 
import org.neo4j.graphdb.Transaction; 
import java.util.Iterator; 
import org.neo4j.helpers.collection.IteratorUtil; 




import com.neo4j.enitites.Global; 

public class FetchData { 
    public static void main(String[] args) throws Exception 
     { 

     String nodeResult = null; 
     try (Transaction ignored = Global.db.beginTx(); 
        Result result = Global.db.execute("MATCH path=()-[:route_1*]-() RETURN nodes(path) AS result")) 
      { 
       // START SNIPPET: items 
       Iterator<Node> n_column = result.columnAs("result"); 
       for (Node node : IteratorUtil.asIterable(n_column)) 
       { 
        nodeResult = node + ": " + node.getProperty("StationCode"); 
       } 
       // END SNIPPET: items 


      } 

     System.out.println(nodeResult); 
     } 
} 

我已經搜索了錯誤,但只有2或3個職位是那裏還沒有工作。有沒有人遇到過這個問題,或者這個代碼有什麼問題。 感謝

回答

0

使用此片段,而不是事務中嘗試,與資源塊:

 for (Object cell : IteratorUtil.asIterable(result.columnAs("result"))) { 
      Iterable<Node> nodes = (Iterable<Node>) cell; 
      for (Node n : nodes) { 
       System.out.println(n); 
      } 
     } 
+0

謝謝,它的工作:) –