문제

I am trying to use spring in my android app as client of my spring mvc REST application. I think I have a problem to put correct jars in classpath of my android app. I put the image of jars in libs folder of my android app. I found many related question on SO. But none of them helped me. That is why i am asking here again.

enter image description here

Here is how I am calling my webservice referenced from here :

@Override
protected SowResult doInBackground(Void... params) {
    System.out.println("URLLLL : "+URL);
    RestTemplate rest = new RestTemplate();
    rest.getMessageConverters().add(new MappingJacksonHttpMessageConverter());
    SowResult result = rest.getForObject(URL, SowResult.class);
    return result;
}

And the exception I am getting:

FATAL EXCEPTION: AsyncTask #1
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:200)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
at java.lang.Thread.run(Thread.java:1096)
Caused by: java.lang.NoSuchMethodError: org.codehaus.jackson.map.ObjectMapper.getTypeFactory
at org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.getJavaType(MappingJacksonHttpMessageConverter.java:166)
at org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.canRead(MappingJacksonHttpMessageConverter.java:101)
at org.springframework.web.client.RestTemplate$AcceptHeaderRequestCallback.doWithRequest(RestTemplate.java:542)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:474)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:439)
at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:237)
at com.inovarge.shoponway.resttasks.UserRestTask.doInBackground(UserRestTask.java:30)
at com.inovarge.shoponway.resttasks.UserRestTask.doInBackground(UserRestTask.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:185)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
... 4 more
도움이 되었습니까?

해결책

The exception indicates that you are missing a required Jackson dependency. First, I recommend using MappingJackson2HttpMessageConverter instead of the MappingJacksonHttpMessageConverter which you've configured:

rest.getMessageConverters().add(new MappingJackson2HttpMessageConverter());

Next, MappingJackson2HttpMessageConverter depends on the Jackson 2 library for its functionality, which requires the following files be on your classpath:

  • jackson-databind-2.3.2.jar
  • jackson-annotations-2.3.2.jar
  • jackson-core-2.3.2.jar

You already have jackson-databind-2.3.2.jar in your libs folder, so you need to download the other two jars.

Lastly, I highly recommend using a dependency management system like the Gradle plugin in Android's New Build System. It will handle downloading all the transitive dependencies for you instead of having to manually do that.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top