[英]java.lang.NoClassDefFoundError: org/apache/http/conn/params/ConnPerRoute
I am receiving java.lang.NoClassDefFoundError: org/apache/http/conn/params/ConnPerRoute 我收到java.lang.NoClassDefFoundError:org / apache / http / conn / params / ConnPerRoute
This error is occurring as I attempt to use the Spring, Android REST framework. 当我尝试使用Spring Android REST框架时,会发生此错误。 The code is fairly simple and is given below. 该代码非常简单,如下所示。
It seems to me that this issue should be a dependency issue, but I have included both the required Spring dependencies and org.apache.httpcomponents', 'httpclient-android' dependency the issue has persisted. 在我看来,这个问题应该是一个依赖关系问题,但是我同时包含了必需的Spring依赖关系和org.apache.httpcomponents','httpclient-android'依赖关系,这个问题仍然存在。
I am at a loss on how to proceed. 我对如何进行一无所知。 A snippet of the problem code is below, along with my build.gradle file, and the full exception printout. 下面是问题代码的片段,以及我的build.gradle文件和完整的异常打印输出。
Can anyone help me resolve this issue? 谁能帮我解决这个问题? Many thanks. 非常感谢。
Error: 错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/conn/params/ConnPerRoute
at org.springframework.http.client.support.HttpAccessor.<init>(HttpAccessor.java:71)
at org.springframework.http.client.support.InterceptingHttpAccessor.<init>(InterceptingHttpAccessor.java:36)
at org.springframework.web.client.RestTemplate.<init>(RestTemplate.java:156)
at com.lazeebear.ServerConnector.ServerConnector.signin(ServerConnector.java:27)
at com.lazeebear.main.main(main.java:12)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.lang.ClassNotFoundException: org.apache.http.conn.params.ConnPerRoute
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 10 more
Code: public static boolean signin(String email, String password) { 代码:公共静态布尔值登录(字符串电子邮件,字符串密码){
// Define endpoint
String url = baseURL + signinEndpoint;
// Create parameters for POST request
String parameters = "?email=" + email + "&password=" + password;
// Make POST request
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<Object> entity = restTemplate.postForEntity(url, getHeaders(), Object.class, parameters);
// Get and set cookies
List<String> cookies = entity.getHeaders().get(COOKIES_HEADER);
setCookies(cookies);
HttpStatus status = entity.getStatusCode();
if (status.equals(HttpStatus.OK)) {
return true;
}
else {
return false;
}
}
build.gradle: apply plugin: 'com.android.application' build.gradle:应用插件:“ com.android.application”
android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
defaultConfig {
applicationId "com.lazeebear"
minSdkVersion 19
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
testCompile 'junit:junit:4.12'
// Dependencies for payment
compile 'com.braintreepayments.api:braintree:2.+'
compile 'com.braintreepayments.api:drop-in:2.+'
// Dependencies for Spring
compile 'org.springframework.android:spring-android-rest-template:2.0.0.M3'
compile 'com.fasterxml.jackson.core:jackson-databind:2.3.2'
// Dependencies for GSON
compile group: 'com.google.code.gson', name: 'gson', version: '2.4'
// Test
compile group: 'org.apache.httpcomponents', name: 'httpclient-android', version: '4.3.3'
}
If you look at the contents of the httpclient-android JAR then that class does not exist. 如果您查看httpclient-android JAR的内容,则该类不存在。
That class does however exist in: 该类确实存在于:
org.apache.httpcomponents http-client JAR. org.apache.httpcomponents http-client JAR。
http://www.findjar.com/class/org/apache/http/conn/params/ConnPerRoute.html http://www.findjar.com/class/org/apache/http/conn/params/ConnPerRoute.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.