我在Android项目中遇到这个烦人的异常。我想要做的是将json发布到我的休息服务。我的问题是我无法使用MappingJackson2HttpMessageConverter。无论我做什么,都不断抛出异常:
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
我没有使用Maven或Gradle,我不想这样做。这是我添加的tha罐子。我不认为我错过了什么。
您是否知道导致问题的原因以及解决方法?如果您需要更多信息,请随时询问。谢谢!
答案 0 :(得分:0)
Okey,当我将MappingJackson2HttpMessageConverter更改为GsonHttpMessageConverter时,它工作正常。这不能解决ClassNotFoundException问题,但它是一个适合我的解决方案。