简体   繁体   中英

Connect to Neo4J with Android

I am trying to connect to my localhost (Neo4J database) from an Android application.

The way to do this, is using a few libraries:

  • neo4J-rest-graphdb-1.8.1.jar
  • neo4J-rest-graphdb-1.8.1-javadoc-.jar
  • neo4J-rest-graphdb-1.8.1-sources.jar
  • neo4J-rest-graphdb-1.8.1-test-sources.jar
  • neo4J-rest-graphdb-1.8.1-tests.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:

    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.

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. I already tried to install Maven.. But that wont install via the marketplace it says that its missing repositories.

Any help would be great!

You should look here, How can I access my localhost from my Android device?

You can not connect to your local server from Android Emulator with "localhost". You need use this ip 10.0.2.2,

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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