Android应用程序中的java.lang.NoSuchMethodError

时间:2015-02-16 21:41:19

标签: java android jdbc neo4j nosuchmethoderror

我正在尝试通过Android应用程序(使用Android Studio)使用Java JDBC驱动程序连接到我的Neo4j服务器。它在Eclipse中工作正常,但是在这里我收到一个错误:java.lang.NoSuchMethodError。我添加了JDBC jar文件,我正在搜索,似乎Android正在使用过时的HttpClient版本。我从https://code.google.com/p/httpclientandroidlib/下载了文件并添加了jar但错误并没有消失。这是我的代码和堆栈跟踪:

Class.forName("org.neo4j.jdbc.Driver");

        Connection con = null;

        con = DriverManager.getConnection("jdbc:neo4j://xxx.xxx:7474"); --> This is where error is (name of server hidden for security)


        // Querying
        try(Statement stmt = con.createStatement()) {
            ResultSet rs = stmt.executeQuery("MATCH (n:Manager) RETURN n.Email");
            while (rs.next()) {
                Toast.makeText(this, rs.getString("n.Email"), Toast.LENGTH_SHORT).show();
                // System.out.println(rs.getString("n.Email"));
            }
        }

堆栈跟踪:

 java.lang.IllegalStateException: Could not execute method of the activity
            at android.view.View$1.onClick(View.java:3855)
            at android.view.View.performClick(View.java:4470)
            at android.view.View$PerformClick.run(View.java:18593)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:157)
            at android.app.ActivityThread.main(ActivityThread.java:5867)
            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:858)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:674)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.reflect.InvocationTargetException
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at android.view.View$1.onClick(View.java:3850)
            at android.view.View.performClick(View.java:4470)
            at android.view.View$PerformClick.run(View.java:18593)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:157)
            at android.app.ActivityThread.main(ActivityThread.java:5867)
            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:858)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:674)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NoSuchMethodError: org.apache.http.conn.ssl.SSLSocketFactory.<init>
            at org.restlet.ext.httpclient.HttpClientHelper.configure(HttpClientHelper.java:275)
            at org.restlet.ext.httpclient.HttpClientHelper.start(HttpClientHelper.java:478)
            at org.restlet.Client.start(Client.java:217)
            at org.restlet.Restlet.handle(Restlet.java:315)
            at org.restlet.Client.handle(Client.java:177)
            at org.restlet.resource.ClientResource.handle(ClientResource.java:1136)
            at org.restlet.resource.ClientResource.handleOutbound(ClientResource.java:1225)
            at org.restlet.resource.ClientResource.handle(ClientResource.java:1068)
            at org.restlet.resource.ClientResource.handle(ClientResource.java:1044)
            at org.restlet.resource.ClientResource.handle(ClientResource.java:950)
            at org.restlet.resource.ClientResource.get(ClientResource.java:658)
            at org.neo4j.jdbc.rest.Resources$DiscoveryClientResource.readInformation(Resources.java:131)
            at org.neo4j.jdbc.rest.Resources.getDiscoveryResource(Resources.java:65)
            at org.neo4j.jdbc.rest.Resources.getDiscoveryResource(Resources.java:60)
            at org.neo4j.jdbc.Neo4jConnection.getDiscoveryResource(Neo4jConnection.java:80)
            at org.neo4j.jdbc.Neo4jConnection.createExecutor(Neo4jConnection.java:69)
            at org.neo4j.jdbc.Neo4jConnection.<init>(Neo4jConnection.java:61)
            at org.neo4j.jdbc.Connections$4.doCreate(Connections.java:51)
            at org.neo4j.jdbc.Connections.create(Connections.java:62)
            at org.neo4j.jdbc.Driver.connect(Driver.java:64)
            at org.neo4j.jdbc.Driver.connect(Driver.java:36)
            at java.sql.DriverManager.getConnection(DriverManager.java:179)
            at java.sql.DriverManager.getConnection(DriverManager.java:144)
            at computing.gmit.ie.scorerapp.Login.btnLoginClick(Login.java:45)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at android.view.View$1.onClick(View.java:3850)
            at android.view.View.performClick(View.java:4470)
            at android.view.View$PerformClick.run(View.java:18593)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:157)
            at android.app.ActivityThread.main(ActivityThread.java:5867)
            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:858)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:674)
            at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:1)

我猜这与你在运行时动态加载该类的方式有关。如果您正在运行pro-guard并且您的代码被混淆,则可能是问题。

尝试将库添加到项目中并像平常一样导入类。