发布Node neo4j的问题 [英] Issue of casting Node neo4j

查看:94
本文介绍了发布Node neo4j的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码在下面,根据文档,它应该给我节点值,但会抛出异常

My code is below, As per the documentation it should have given me the node values but it is throwing me exception

Exception in thread "main" java.lang.ClassCastException: scala.collection.convert.Wrappers$SeqWrapper cannot be cast to org.neo4j.graphdb.Node
	at com.neo4j.performance.FetchData.main(FetchData.java:32)

我正在使用Neo4j 2.2.2.

I'm using 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个帖子在那里也无法正常工作.有没有人遇到这个问题,或者这段代码有问题. 谢谢

I've searched for the error but only 2 or 3 posts are there those also not working. Has anyone came across with this issue or there is something wrong in this code. Thanks

推荐答案

在交易try-with-resources块中使用以下代码段代替:

Use this snippet instead inside the transaction try-with-resources block:

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

这篇关于发布Node neo4j的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆