NoClassDefFondError在Android的...但类是在一个罐子包含在类路径是在、罐子、路径、NoClassDefFondError

2023-09-04 04:44:52 作者:死党不一定要死

我开发一个应用程序在Android中。它必须能够对拍摄的照片,并发送照片的网页。这是code:

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);

我需要在我的类路径(HttpClient的,Apache的mime4j核心,的HttpCore和httpmime)库。它不会显示在编译时错误。但是,当我运行该项目,它说:java.lang.NoClassDefFoundError的:org.apache.http.entity.mime.MultipartEntity,但在坛子里存在的类并(在httpMime,完全一致)。下面是完整的跟踪:

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)

我已经试过与旧版本都在这个任务中使用的罐子,但它仍然不工作。那罐子也出现在Android项目的引用的库。

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.

感谢你在前进!

推荐答案

您需要创建一个名为在项目文件夹,拷贝引用罐子到这个文件夹。

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