NoClassDefFoundError with org.apache packages

129 views
Skip to first unread message

Daniel

unread,
Apr 26, 2011, 5:02:42 AM4/26/11
to Robolectric
Hi,

We are trying to integrate robolectric in our project but have runned
into some unexpected problems.

The project compiles fine when we're not using Robolectric. However,
we are getting NoClassDefFoundError in the org.apache.http packages
when running simple tests with Robolectric.


Exception in thread "Thread-1" java.lang.NoClassDefFoundError: org/
apache/http/HttpRequest
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.lang.ClassLoader.defineClass(ClassLoader.java:466)
at javassist.Loader.findClass(Loader.java:379)
at
com.xtremelabs.robolectric.bytecode.RobolectricClassLoader.findClass(RobolectricClassLoader.java:
60)
at javassist.Loader.loadClass(Loader.java:311)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at
com.xtremelabs.robolectric.bytecode.RobolectricClassLoader.loadClass(RobolectricClassLoader.java:
37)
at se.hsr.android.Info.updateInfoFromWebService(Info.java:57)
at se.hsr.android.Info$2.run(Info.java:99)
Caused by: java.lang.ClassNotFoundException: caught an exception while
obtaining a class file for org.apache.http.HttpRequest
at javassist.Loader.findClass(Loader.java:359)
at
com.xtremelabs.robolectric.bytecode.RobolectricClassLoader.findClass(RobolectricClassLoader.java:
60)
at javassist.Loader.loadClass(Loader.java:311)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at
com.xtremelabs.robolectric.bytecode.RobolectricClassLoader.loadClass(RobolectricClassLoader.java:
37)
... 11 more
Caused by: java.lang.IllegalStateException: shouldn't be modifying
bytecode after we've started writing cache!
class=org.apache.http.HttpRequest
at
com.xtremelabs.robolectric.bytecode.AndroidTranslator.onLoad(AndroidTranslator.java:
68)
at javassist.Loader.findClass(Loader.java:340)
... 15 more

We are using maven to build our project and we have included http-
client 4.1 (because we are dependent on http-mime 4.1 from the apache
library).

Since the Robolectric jar as default includes httpclient 4.0.3 we
can't understand why it can't find the http classes. We assume it has
something to do with AndroidTranslator trying to modify bytecode (to
be compatible with the dalvik jvm?)

If someone could shed some light on this matter we would be very
grateful.
Reply all
Reply to author
Forward
0 new messages