ComputerScientist ComputerScientist - 3 months ago 9
Java Question

Attempting to run neo4j tutorial, get error: error: no suitable method found for run(String,Map<String,List>)

I am just learning how to use Neo4j. I went on their website and saw one of their tutorials. On that website, if you scroll down, you'll see their "Test-Drive Neo4j with Cypher" section, and the default one ("Social") has a "Friends of Friends" example. Furthermore, they have some code examples. I clicked on the "Java" one and saw an example of the

Social.java
program. Their instructions had four parts:


  1. Download a Neo4j driver (they provide the link, and I downloaded that JAR)

  2. Copy and paste code into
    Social.java

  3. Compile with
    javac -cp neo4j-java-driver-1.0.0.jar Social.java

  4. Run with
    java -cp neo4j-java-driver-1.0.0.jar:. Social



Unfortunately, step (3) fails. After trying to compile, I get the following error:

javac -cp neo4j-java-driver-1.0.0.jar Social.java Social.java:25: error: no suitable method found for run(String,Map<String,List>)
session.run(insertQuery,singletonMap("pairs",data)).consume();
^
method StatementRunner.run(Statement) is not applicable
(actual and formal argument lists differ in length)
method StatementRunner.run(String) is not applicable
(actual and formal argument lists differ in length)
method StatementRunner.run(String,Record) is not applicable
(actual argument Map<String,List> cannot be converted to Record by method invocation conversion)
method StatementRunner.run(String,Map<String,Object>) is not applicable
(actual argument Map<String,List> cannot be converted to Map<String,Object> by method invocation conversion)
method StatementRunner.run(String,Value) is not applicable
(actual argument Map<String,List> cannot be converted to Value by method invocation conversion) 1 error


I'm not sure how to fix it because I don't know the details of the
run
method, and I assumed that since this was a tutorial with four simple steps, all stages should have worked correctly. My
javac
version is 1.7, if that matters.

Is there something obvious I am missing?

Answer

Thanks for reporting this, it looks like an error in the examples. You can create a hashmap yourself instead of using the singletonMap causing the issue :

Map<String, Object> parameters = new HashMap<>();
parameters.put("pairs", data);

session.run(insertQuery,parameters).consume();