简体   繁体   English

使用Android连接到Neo4J

[英]Connect to Neo4J with Android

I am trying to connect to my localhost (Neo4J database) from an Android application. 我正在尝试从Android应用程序连接到我的本地主机(Neo4J数据库)。

The way to do this, is using a few libraries: 为此,使用一些库:

  • neo4J-rest-graphdb-1.8.1.jar neo4J-rest-graphdb-1.8.1.jar
  • neo4J-rest-graphdb-1.8.1-javadoc-.jar neo4J-rest-graphdb-1.8.1-javadoc-.jar
  • neo4J-rest-graphdb-1.8.1-sources.jar neo4J-rest-graphdb-1.8.1-sources.jar
  • neo4J-rest-graphdb-1.8.1-test-sources.jar neo4J-rest-graphdb-1.8.1-test-sources.jar
  • neo4J-rest-graphdb-1.8.1-tests.jar neo4J-rest-graphdb-1.8.1-tests.jar
  • neo4j-server-1.8.M03.jar neo4j-server-1.8.M03.jar

When I add those libraries to my Java Build Path it can use them to connect to the Neo4J database, like this: 当我将这些库添加到Java Build Path时,它可以使用它们连接到Neo4J数据库,如下所示:

    import org.neo4j.rest.graphdb.RestAPI;
    import org.neo4j.rest.graphdb.RestAPIFacade;
    import org.neo4j.rest.graphdb.query.QueryEngine;
    import org.neo4j.rest.graphdb.query.RestCypherQueryEngine;
    import org.neo4j.rest.graphdb.util.QueryResult;

    RestAPI graphDb = new RestAPIFacade("http://localhost:7474/db/data");

    QueryEngine engine=new RestCypherQueryEngine(graphDb);                  
    QueryResult<Map<String,Object>> result = engine.query("create (:Person {name:\"Steve\"}) return n", Collections.EMPTY_MAP); 
    Iterator<Map<String, Object>> iterator=result.iterator(); 

     if(iterator.hasNext()) {       
       Map<String,Object> row= iterator.next();            

       int duration = Toast.LENGTH_LONG;
        Toast toast = Toast.makeText(getApplicationContext(),"" + row.get("total") , duration);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();           
     }

The problem is that I keep getting an error: NoClassDefFoundError org.neo4j.rest.graphdb.RestAPIFacade. 问题是我不断收到错误:NoClassDefFoundError org.neo4j.rest.graphdb.RestAPIFacade。

I think it's because of missing a jar file for the build path... But I am not sure.. Maybe something else is going wrong. 我认为这是因为缺少构建路径的jar文件...但是我不确定..也许其他地方出了问题。 I already tried to install Maven.. But that wont install via the marketplace it says that its missing repositories. 我已经尝试安装Maven。但是那不会通过它说缺少存储库的市场来安装。

Any help would be great! 任何帮助将是巨大的!

You should look here, How can I access my localhost from my Android device? 您应该在这里查看如何从Android设备访问本地主机?

You can not connect to your local server from Android Emulator with "localhost". 您无法使用“ localhost”从Android仿真器连接到本地服务器。 You need use this ip 10.0.2.2, 您需要使用此IP 10.0.2.2,

RestAPI graphDb = new RestAPIFacade("http://10.0.2.2:7474/db/data");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM