NoClassDefFondError in Android... but the Class is in one jar included in the Classpath

Fustigador picture Fustigador · Apr 9, 2012 · Viewed 13.3k times · Source

I am developing an App in Android. It has to be able of take a photo, and to send that photo to a webpage. This is the code:

HttpClient httpclient = new DefaultHttpClient();

        HttpPost httpPost = new HttpPost("someurl");
        MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); //Here throws the exception
        multipartEntity.addPart("data",
                new InputStreamBody(
                        new ByteArrayInputStream(byteArray),
                        "image/png"));
        multipartEntity.addPart("caption", new StringBody(filename));

        httpPost.setEntity((HttpEntity) multipartEntity);

I have the libraries needed in my ClassPath (httpclient, apache-mime4j-core, httpcore and httpmime). It doesn't shows any error in compilation time. but, when i run the project, it says " java.lang.NoClassDefFoundError: org.apache.http.entity.mime.MultipartEntity" but that class DOES exists in the jars (in httpMime, exactly). Here is the full trace:

04-09 10:21:59.362: E/AndroidRuntime(10352): FATAL EXCEPTION: main
04-09 10:21:59.362: E/AndroidRuntime(10352): java.lang.NoClassDefFoundError: org.apache.http.entity.mime.MultipartEntity
04-09 10:21:59.362: E/AndroidRuntime(10352):    at     com.publidirecta.AppAzafata.IniciarGPSActivity2.enviarImagen(IniciarGPSActivity2.java:206)
04-09 10:21:59.362: E/AndroidRuntime(10352):    at com.publidirecta.AppAzafata.IniciarGPSActivity2.onActivityResult(IniciarGPSActivity2.java:196)
04-09 10:21:59.362: E/AndroidRuntime(10352):    at android.app.Activity.dispatchActivityResult(Activity.java:3908)
04-09 10:21:59.362: E/AndroidRuntime(10352):    at android.app.ActivityThread.deliverResults(ActivityThread.java:2549)
04-09 10:21:59.362: E/AndroidRuntime(10352):    at android.app.ActivityThread.handleSendResult(ActivityThread.java:2595)
04-09 10:21:59.362: E/AndroidRuntime(10352):    at android.app.ActivityThread.access$2000(ActivityThread.java:121)
04-09 10:21:59.362: E/AndroidRuntime(10352):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:973)
04-09 10:21:59.362: E/AndroidRuntime(10352):    at android.os.Handler.dispatchMessage(Handler.java:99)
04-09 10:21:59.362: E/AndroidRuntime(10352):    at android.os.Looper.loop(Looper.java:130)
04-09 10:21:59.362: E/AndroidRuntime(10352):    at  android.app.ActivityThread.main(ActivityThread.java:3701)
04-09 10:21:59.362: E/AndroidRuntime(10352):    at java.lang.reflect.Method.invokeNative(Native Method)
04-09 10:21:59.362: E/AndroidRuntime(10352):    at java.lang.reflect.Method.invoke(Method.java:507)
04-09 10:21:59.362: E/AndroidRuntime(10352):    at     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
04-09 10:21:59.362: E/AndroidRuntime(10352):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
04-09 10:21:59.362: E/AndroidRuntime(10352):    at dalvik.system.NativeStart.main(Native Method)

I've tried with older versions of all the jars used in this task, but it still doesn't works. That jars do appear in the "referenced Libraries" in the Android project.

I've tried everything. Anybody has any idea why this happens? im about to throw myself for the window.

Thank you in advance!

Answer

idiottiger picture idiottiger · Apr 9, 2012

you need create a folder named libs in your project, and copy you referenced jars to this folder.