Reputation: 15
I'm programming an app in Android but I can´t connect it to a local neo4j database.
In the gradle I've put this dependencies:
compile 'org.neo4j.driver:neo4j-java-driver:1.4.1'
compile 'org.neo4j:neo4j-jdbc:3.1.0'
The connection code is the following:
import org.neo4j.driver.v1.Driver;
import org.neo4j.driver.v1.GraphDatabase;
import org.neo4j.driver.v1.Session;
import org.neo4j.driver.v1.StatementResult;
import static org.neo4j.driver.v1.Values.parameters;
public class ConsultasBD {
@TargetApi(Build.VERSION_CODES.KITKAT)
public static boolean consultaLogin(String u, String p) {
try {
// Connect
Driver driver = GraphDatabase.driver( "bolt://192.168.0.39:7474");
Session session = driver.session();
// Querying
StatementResult result = session.run( "MATCH (a:Person {usr: {name}, Pass: {pass}})",
parameters( u, p ) );
while ( result.hasNext() )
{
System.out.println("OK");
}
session.close();
driver.close();
} catch (Exception ex) {
ex.printStackTrace();
return false;
}
return true;
}
}
But when I run it, I get this exception:
java.lang.NoClassDefFoundError: Failed resolution of: Ljava/net/StandardSocketOptions;
And I don't know how can I fix it.
Can anyone explain me how can I connect my app with neo4j?
Thank you very much.
Miguel
Upvotes: 0
Views: 238
Reputation: 67019
StandardSocketOptions was only added to Android in API level 24 (Nougat). So, unless you have a device with API level 24 or higher, you will get that exception.
However, even if you do run your app on such a device, there may be other needed classes that are missing. This is because the neo4j Java libraries do not attempt to target the Android environment (which only supports part of the standard Java libraries). So, this kind of problem is to be expected. Android apps should use the neo4j HTTP API instead.
Upvotes: 2