当我在.addpart中使用MultipartEntityBuilder时,应用程序崩溃

时间:2014-09-24 21:09:50

标签: android android-studio httpclient multipartentity

您好我正在尝试将文件发送到我的服务器。这是代码:

 File file = new File(Environment.getExternalStorageDirectory(),"/sdcard/img.jpg");
                    HttpClient http = AndroidHttpClient.newInstance("MyApp");
                    HttpPost method = new HttpPost(Constants.fakeURL);
                    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
                    builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
                     FileBody bin = new FileBody(file);
                    builder.addPart("file",bin);
                    HttpEntity entity = builder.build();
                   method.setEntity(entity);
                    HttpResponse response = http.execute(method);

但它崩溃了

  

FileBody bin = new FileBody(file);

错误是:

  

致命异常:Thread-3618       处理:com.example.hroshandel.myapplication,PID:24617       java.lang.NoClassDefFoundError:org.apache.http.entity.ContentType               在org.apache.http.entity.mime.content.FileBody。(FileBody.java:89)               在com.example.hroshandel.myapplication.uploadDataFragment $ 2.run(uploadDataFragment.java:149)               在java.lang.Thread.run(Thread.java:841)   09-24 14:09:26.946 24617-24626 / com.example.hroshandel.myapplication E / AndroidHttpClient:泄漏发现       java.lang.IllegalStateException:AndroidHttpClient已创建且从未关闭               在android.net.http.AndroidHttpClient。(AndroidHttpClient.java:214)               在android.net.http.AndroidHttpClient.newInstance(AndroidHttpClient.java:200)               在android.net.http.AndroidHttpClient.newInstance(AndroidHttpClient.java:209)               在com.example.hroshandel.myapplication.uploadDataFragment $ 2.run(uploadDataFragment.java:145)               在java.lang.Thread.run(Thread.java:841)

1 个答案:

答案 0 :(得分:2)

我发现了问题。我不得不去hc.apache.org/downloads.cgi并下载core,mime,client和cache并包含库