Android Spring ClassNotFoundException For ObjectMa

2019-09-07 07:43发布

I'm having this annoying exception in my Android project. What I'm trying to do is to post json to my rest service. My problem is that I can't use the MappingJackson2HttpMessageConverter. Whatever I do it keeps throwing an exception:

04-27 19:58:33.124: E/AndroidRuntime(12924): FATAL EXCEPTION: AsyncTask #2
04-27 19:58:33.124: E/AndroidRuntime(12924): Process: com.restclient.trafficspy, PID: 12924
04-27 19:58:33.124: E/AndroidRuntime(12924): java.lang.RuntimeException: An error occured while executing doInBackground()
04-27 19:58:33.124: E/AndroidRuntime(12924):    at android.os.AsyncTask$3.done(AsyncTask.java:304)
04-27 19:58:33.124: E/AndroidRuntime(12924):    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
04-27 19:58:33.124: E/AndroidRuntime(12924):    at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
04-27 19:58:33.124: E/AndroidRuntime(12924):    at java.util.concurrent.FutureTask.run(FutureTask.java:242)
04-27 19:58:33.124: E/AndroidRuntime(12924):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
04-27 19:58:33.124: E/AndroidRuntime(12924):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
04-27 19:58:33.124: E/AndroidRuntime(12924):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
04-27 19:58:33.124: E/AndroidRuntime(12924):    at java.lang.Thread.run(Thread.java:818)
04-27 19:58:33.124: E/AndroidRuntime(12924): Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/fasterxml/jackson/databind/ObjectMapper;
04-27 19:58:33.124: E/AndroidRuntime(12924):    at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.<init>(MappingJackson2HttpMessageConverter.java:55)
04-27 19:58:33.124: E/AndroidRuntime(12924):    at com.restclient.trafficspy.RestServiceClient.doInBackground(RestServiceClient.java:51)
04-27 19:58:33.124: E/AndroidRuntime(12924):    at com.restclient.trafficspy.RestServiceClient.doInBackground(RestServiceClient.java:1)
04-27 19:58:33.124: E/AndroidRuntime(12924):    at android.os.AsyncTask$2.call(AsyncTask.java:292)
04-27 19:58:33.124: E/AndroidRuntime(12924):    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
04-27 19:58:33.124: E/AndroidRuntime(12924):    ... 4 more
04-27 19:58:33.124: E/AndroidRuntime(12924): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.fasterxml.jackson.databind.ObjectMapper" on path: DexPathList[[zip file "/data/app/com.restclient.trafficspy-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
04-27 19:58:33.124: E/AndroidRuntime(12924):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
04-27 19:58:33.124: E/AndroidRuntime(12924):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
04-27 19:58:33.124: E/AndroidRuntime(12924):    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
04-27 19:58:33.124: E/AndroidRuntime(12924):    ... 9 more
04-27 19:58:33.124: E/AndroidRuntime(12924):    Suppressed: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.ObjectMapper
04-27 19:58:33.124: E/AndroidRuntime(12924):        at java.lang.Class.classForName(Native Method)
04-27 19:58:33.124: E/AndroidRuntime(12924):        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
04-27 19:58:33.124: E/AndroidRuntime(12924):        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
04-27 19:58:33.124: E/AndroidRuntime(12924):        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
04-27 19:58:33.124: E/AndroidRuntime(12924):        ... 10 more
04-27 19:58:33.124: E/AndroidRuntime(12924):    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

I'm not using Maven or Gradle and I don't want to. Here are tha jars that I have added. I don't think I'm missing something.

Do you have any idea what causes the problem and how to fix it? Feel free to ask if you need more information. Thanks!

1条回答
你好瞎i
2楼-- · 2019-09-07 08:10

Okey, It worked when I changed MappingJackson2HttpMessageConverter to GsonHttpMessageConverter. This doesn't solve the ClassNotFoundException problem but it is a solution that works for me.

查看更多
登录 后发表回答