我正在开发一个 Android 应用程序。它必须能够拍照,并将该照片发送到网页。这是代码:
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);
我的 ClassPath 中有所需的库(httpclient、apache-mime4j-core、httpcore 和 httpmime)。它在编译时没有显示任何错误。但是,当我运行该项目时,它显示“java.lang.NoClassDefFoundError: org.apache.http.entity.mime.MultipartEntity”但该类确实存在于罐子中(确切地说是在 httpMime 中)。这是完整的跟踪:
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)
我已尝试使用此任务中使用的所有 jar 的旧版本,但它仍然无法正常工作。这些 jar 确实出现在 Android 项目的“引用的库”中。
我什么都试过了。有人知道为什么会这样吗?我正要扑向窗户。
先感谢您!