In my android application i am making service call using resttemplate, but the problem is now i am getting below error when any services get called.The services are not connecting to the server.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.lss.company, PID: 8611
java.lang.NoClassDefFoundError: org.springframework.web.util.UriTemplate
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:498)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:447)
at com.lss.company.services.ServerAuthenticateService.getAllEmployeeList(ServerAuthenticateService.java:7320)
at com.lss.company.view.LoginActivity.onCreate(LoginActivity.java:138)
at android.app.Activity.performCreate(Activity.java:5459)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2458)
at android.app.ActivityThread.access$900(ActivityThread.java:172)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1305)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5598)
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:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Below is the build.gradle dependency codes
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.lss.company"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
}
lintOptions {
checkReleaseBuilds false
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
}
}
dexOptions {
javaMaxHeapSize "4g"
}
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'])
compile 'com.android.support:appcompat-v7:26.0.0'
compile 'com.android.support:design:26.0.0'
compile 'com.android.support:cardview-v7:26.0.0'
compile 'com.android.support:recyclerview-v7:26.0.0'
compile 'org.springframework.android:spring-android-rest-template:2.0.0.M3'
compile 'org.springframework.android:spring-android-core:2.0.0.M3'
compile 'joda-time:joda-time:2.3'
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.0'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.9.0'
compile 'com.fasterxml.jackson.core:jackson-core:2.9.0'
compile 'com.google.code.gson:gson:2.8.1'
compile 'com.android.support:multidex:1.0.1'
compile 'net.sourceforge.jexcelapi:jxl:2.6.12'
compile 'com.getbase:floatingactionbutton:1.10.1'
compile 'com.github.ganfra:material-spinner:2.0.0'
compile 'com.github.wseemann:FFmpegMediaMetadataRetriever:1.0.14'
compile 'commons-io:commons-io:1.3.2'
compile 'de.hdodenhof:circleimageview:2.2.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
testCompile 'junit:junit:4.12'
}
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '26.1.0'
}
}
}
}
There was no error till now and all of my services are working but suddenly this error came out and it's not allowing me to continue.Below is the call to the server.
public List<Employee> getAllEmployeeList() {
String plainClientCredentials="************************";
String base64ClientCredentials = new String(Base64.encode(plainClientCredentials.getBytes(),Base64.NO_WRAP));
HttpHeaders headers = new HttpHeaders();
headers.add("Authorization", "Basic " + base64ClientCredentials);
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
HttpEntity<String> entity = new HttpEntity<String>(headers);
ResponseEntity<String> restRes = restTemplate.exchange(LoginActivity.strMainUrl+"protected/users/getAllEmployeeList", HttpMethod.GET, entity, String.class);
System.out.println("restRes : "+restRes);
if (restRes.getStatusCode() == HttpStatus.OK) {
AppBackupCache.checkToken = 200;
String resBody = restRes.getBody();
Type listType = new TypeToken<List<Employee>>() {}.getType();
List<Employee> employeeList = new ArrayList<Employee>();
schoolList = gson.fromJson(resBody,listType);
return employeeList;
} else if(restRes.getStatusCode() == HttpStatus.UNAUTHORIZED) {
AppBackupCache.checkToken = 401;
return null;
} else {
AppBackupCache.checkToken = 402;
return null;
}
}
Above code was working fine till now and suddenly the error came and its not working,same happens in every service calls.What is wrong in my code. Below is the way i am calling other services from activity classes.
if (AppBackupCache.isServerReachable(getApplicationContext())) {
this.sectionList = serverAuthenticateService.getAllDepartmentList(this.authtoken, getApplicationContext(), this.companyUrl);
if (AppBackupCache.checkToken == ItemTouchHelper.Callback.DEFAULT_DRAG_ANIMATION_DURATION) {
showDepartmentSpinner();
} else if (AppBackupCache.checkToken == 401) {
this.manager.invalidateAuthToken("com.lss.company", this.authtoken);
this.authtoken = null;
final AccountManagerFuture<Bundle> future = this.manager.getAuthToken(this.mAccount, AccountGeneral.AUTHTOKEN_TYPE_FULL_ACCESS, true, null, null);
new Thread(new Runnable() {
public void run() {
try {
Bundle bnd = (Bundle) future.getResult();
StaffActivity.this.authtoken = bnd.getString("authtoken");
if (StaffActivity.this.authtoken != null) {
StaffActivity.this.sectionList = serverAuthenticateService.getAllDepartmentList(StaffActivity.this.authtoken, StaffActivity.this.getApplicationContext(), StaffActivity.this.companyUrl);
if (AppBackupCache.checkToken == ItemTouchHelper.Callback.DEFAULT_DRAG_ANIMATION_DURATION) {
StaffActivity.this.showDepartmentSpinner();
return;
}
StaffActivity.this.getMsgBox("Error", "Something went wrong");
return;
}
System.out.println("************** NULL *****************");
StaffActivity.this.getMsgBox("", "Token not refreshed....");
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
AppBackupCache.checkToken = 401;
return;
}
getMsgBox("No connection", "No connection");
service class :
public class ServerAuthenticateService implements ServerAuthenticate {
String authAToken = null;
Gson gson;
RestTemplate restTemplate;
public List<Departments> getAllDepartmentList(String authToken, Context applicationContext, String companyUrl) {
MultiValueMap headers = new HttpHeaders();
System.out.println("authToken " + authToken);
headers.set(HttpHeaders.AUTHORIZATION, "bearer " + authToken);
ResponseEntity<String> restRes = this.restTemplate.exchange(companyUrl + "protected/users/getAllDepartmentList", HttpMethod.POST, new HttpEntity(headers), String.class, new Object[0]);
if (restRes.getStatusCode() == HttpStatus.OK) {
AppBackupCache.checkToken = Callback.DEFAULT_DRAG_ANIMATION_DURATION;
String resBody = (String) restRes.getBody();
Type listType = new C07736().getType();
List<Departments> catList = new ArrayList();
return (List) this.gson.fromJson(resBody, listType);
} else if (restRes.getStatusCode() == HttpStatus.UNAUTHORIZED) {
AppBackupCache.checkToken = 401;
return null;
} else {
AppBackupCache.checkToken = 402;
return null;
}
}
public ServerAuthenticateService() {
try {
restTemplate = new RestTemplate();
List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
messageConverters.add(new StringHttpMessageConverter());
messageConverters.add(new FormHttpMessageConverter());
restTemplate.setMessageConverters(messageConverters);
restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
protected boolean hasError(HttpStatus statusCode) {
return false;
}
});
GsonBuilder builder = new GsonBuilder();
builder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
@Override
public Date deserialize(JsonElement json, Type type, JsonDeserializationContext deserializationContext) throws JsonParseException {
String frStr = json.getAsJsonPrimitive().getAsString();
Date retDate =null;
try {
retDate = dtfDate.parse(frStr);
} catch (ParseException e) {
e.printStackTrace();
}
return retDate;
}
});
builder.registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
@Override
public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
String jsDate = dtf.format(src);
return new JsonPrimitive(jsDate);
}
});
builder.registerTypeAdapter(Timestamp.class, new JsonDeserializer<Timestamp>() {
@Override
public Timestamp deserialize(JsonElement json, Type type, JsonDeserializationContext deserializationContext) throws JsonParseException {
String strDate = json.getAsJsonPrimitive().getAsString();
Date date = null;
try {
date = dtf.parse(strDate);
} catch (ParseException e) {
e.printStackTrace();
}
return new Timestamp(date.getTime());
}
});
builder.registerTypeAdapter(byte[].class, new JsonDeserializer<byte[]>() {
@Override
public byte[] deserialize(JsonElement json, Type type, JsonDeserializationContext deserializationContext) throws JsonParseException {
return Base64.decode(json.getAsString(), Base64.NO_WRAP);
}
});
gson = builder.create();
} catch (Exception e) {
e.printStackTrace();
}
}
}
from java.lang.NoClassDefFoundError: org.springframework.web.util.UriTemplate
No comments:
Post a Comment