我想在我的 Android 项目中使用 neo4j DB。我正在尝试使用 Android 连接 Neo4j 数据库,但连接时出现错误。我在我的 Android 应用级别 gradle 添加了一个依赖项。
compile 'org.neo4j.driver:neo4j-java-driver:1.3.0'
MainActivity.java
Driver driver = GraphDatabase.driver( "bolt://localhost:7687", AuthTokens.basic("neo4j", "neo4j") );
Session session = driver.session();
session.run( "CREATE (a:Person {name: {name}, title: {title}})",
parameters( "name", "Arthur", "title", "King" ) );
StatementResult result = session.run( "MATCH (a:Person) WHERE a.name = {name} " +
"RETURN a.name AS name, a.title AS title",
parameters( "name", "Arthur" ) );
while ( result.hasNext() )
{
Record record = result.next();
System.out.println( record.get( "title" ).asString() + " " + record.get( "name" ).asString() );
}
session.close();
driver.close();
日志
06-22 16:24:05.627 4990-4990/com.example.prateek.neo4jtest E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.prateek.neo4jtest, PID: 4990
java.lang.NoClassDefFoundError: java.net.StandardSocketOptions
at org.neo4j.driver.internal.net.ChannelFactory.create(ChannelFactory.java:39)
at org.neo4j.driver.internal.net.SocketClient.start(SocketClient.java:124)
at org.neo4j.driver.internal.net.SocketConnection.startSocketClient(SocketConnection.java:92)
at org.neo4j.driver.internal.net.SocketConnection.<init>(SocketConnection.java:67)
at org.neo4j.driver.internal.net.SocketConnector.createConnection(SocketConnector.java:77)
at org.neo4j.driver.internal.net.SocketConnector.connect(SocketConnector.java:50)
at org.neo4j.driver.internal.net.pooling.SocketConnectionPool$ConnectionSupplier.get(SocketConnectionPool.java:204)
at org.neo4j.driver.internal.net.pooling.SocketConnectionPool$ConnectionSupplier.get(SocketConnectionPool.java:186)
at org.neo4j.driver.internal.net.pooling.BlockingPooledConnectionQueue.acquire(BlockingPooledConnectionQueue.java:96)
at org.neo4j.driver.internal.net.pooling.SocketConnectionPool.acquireConnection(SocketConnectionPool.java:137)
at org.neo4j.driver.internal.net.pooling.SocketConnectionPool.acquire(SocketConnectionPool.java:76)
at org.neo4j.driver.internal.DirectConnectionProvider.acquireConnection(DirectConnectionProvider.java:45)
at org.neo4j.driver.internal.NetworkSession.acquireConnection(NetworkSession.java:340)
at org.neo4j.driver.internal.NetworkSession.run(NetworkSession.java:104)
at org.neo4j.driver.internal.NetworkSession.run(NetworkSession.java:94)
at com.example.prateek.neo4jtest.MainActivity$1.onClick(MainActivity.java:29)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18431)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5045)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610)
at dalvik.system.NativeStart.main(Native Method)
任何帮助将不胜感激。谢谢!