1

当我尝试使用 Mashape http://blog.mashape.com/using-unirest-java-for-your-android-projects/给出的教程发送请求时。

try
        {
            JsonNode cuerpo=new JsonNode(jsonRespuesta);
            Map<String, String> heads= new HashMap<String,String>();
            heads.put("Content-Type", "application/json");
            heads.put("data_hash", DataSecurity.hashCryptoCode(jsonRespuesta));
            heads.put("Accept","application/json");
            HttpResponse<String> httpResponse= Unirest.post(urls[0])
                    .headers(heads)
                    .body(cuerpo)
                    .asString();
            System.out.println(httpResponse.getStatus());
            System.out.println(httpResponse.getBody());
            return httpResponse.getStatus()+":"+httpResponse.getBody();
        }
        catch (Exception e)
        {
            e.printStackTrace();
            return null;
        }

这是我的毕业生:

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.code.gson:gson:2.3.1'
compile files('libs/unirest-java.jar')}

我得到以下异常。此外,在尝试组装 jar 时,我在测试中遇到错误

Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/naming/ldap/LdapName;
        at com.mashape.relocation.conn.ssl.AbstractVerifier.extractCNs(AbstractVerifier.java:277)
        at com.mashape.relocation.conn.ssl.AbstractVerifier.getCNs(AbstractVerifier.java:265)
        at com.mashape.relocation.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:157)
        at com.mashape.relocation.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:140)
        at com.mashape.relocation.conn.ssl.SSLConnectionSocketFactory.verifyHostname(SSLConnectionSocketFactory.java:301)
        at com.mashape.relocation.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:291)
        at com.mashape.relocation.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:259)
        at com.mashape.relocation.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:125)
        at com.mashape.relocation.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:319)
        at com.mashape.relocation.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:363)
        at com.mashape.relocation.impl.execchain.MainClientExec.execute(MainClientExec.java:219)
        at com.mashape.relocation.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
        at com.mashape.relocation.impl.execchain.RetryExec.execute(RetryExec.java:86)
        at com.mashape.relocation.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
        at com.mashape.relocation.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
        at com.mashape.relocation.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
        at com.mashape.relocation.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106)
        at com.mashape.relocation.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
        at com.mashape.unirest.http.HttpClientHelper.request(HttpClientHelper.java:141)
        at com.mashape.unirest.request.BaseRequest.asString(BaseRequest.java:56)
        at grupo9.arquisoft.migrainetrackingmobile.MainActivity$obtenerToken.doInBackground(MainActivity.java:116)
        at grupo9.arquisoft.migrainetrackingmobile.MainActivity$obtenerToken.doInBackground(MainActivity.java:105)
        at android.os.AsyncTask$2.call(AsyncTask.java:288)
        at java.util.concurrent.FutureTask.run(FutureTask.java:237)

            

继续

Java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:818)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "javax.naming.ldap.LdapName" on path: DexPathList[[zip file "/data/app/grupo9.arquisoft.migrainetrackingmobile-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
            at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
            at com.mashape.relocation.conn.ssl.AbstractVerifier.extractCNs(AbstractVerifier.java:277)
            at com.mashape.relocation.conn.ssl.AbstractVerifier.getCNs(AbstractVerifier.java:265)
            at com.mashape.relocation.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:157)
            at com.mashape.relocation.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:140)
            at com.mashape.relocation.conn.ssl.SSLConnectionSocketFactory.verifyHostname(SSLConnectionSocketFactory.java:301)
            at com.mashape.relocation.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:291)
            at com.mashape.relocation.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:259)
            at com.mashape.relocation.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:125)
            at com.mashape.relocation.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:319)
            at com.mashape.relocation.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:363)
            at com.mashape.relocation.impl.execchain.MainClientExec.execute(MainClientExec.java:219)
            at com.mashape.relocation.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
            at com.mashape.relocation.impl.execchain.RetryExec.execute(RetryExec.java:86)
            at com.mashape.relocation.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
            at com.mashape.relocation.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
            at com.mashape.relocation.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
            at com.mashape.relocation.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106)
            at com.mashape.relocation.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
            at com.mashape.unirest.http.HttpClientHelper.request(HttpClientHelper.java:141)
            at com.mashape.unirest.request.BaseRequest.asString(BaseRequest.java:56)
            at grupo9.arquisoft.migrainetrackingmobile.MainActivity$obtenerToken.doInBackground(MainActivity.java:116)
            at grupo9.arquisoft.migrainetrackingmobile.MainActivity$obtenerToken.doInBackground(MainActivity.java:105)
            at android.os.AsyncTask$2.call(AsyncTask.java:288)
            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
            at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:818)
    Suppressed: java.lang.ClassNotFoundException: javax.naming.ldap.LdapName
            at java.lang.Class.classForName(Native Method)
            at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
            at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:504)

Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
4

0 回答 0