嗨我試圖發送文件到我的服務器。這裏是代碼:當我在.addpart中使用MultipartEntityBuilder時,應用程序崩潰
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);
的錯誤是:
FATAL EXCEPTION: Thread-3618 Process: com.example.hroshandel.myapplication, PID: 24617 java.lang.NoClassDefFoundError: org.apache.http.entity.ContentType at org.apache.http.entity.mime.content.FileBody.(FileBody.java:89) at com.example.hroshandel.myapplication.uploadDataFragment$2.run(uploadDataFragment.java:149) at java.lang.Thread.run(Thread.java:841) 09-24 14:09:26.946 24617-24626/com.example.hroshandel.myapplication E/AndroidHttpClient﹕ Leak found java.lang.IllegalStateException: AndroidHttpClient created and never closed at android.net.http.AndroidHttpClient.(AndroidHttpClient.java:214) at android.net.http.AndroidHttpClient.newInstance(AndroidHttpClient.java:200) at android.net.http.AndroidHttpClient.newInstance(AndroidHttpClient.java:209) at com.example.hroshandel.myapplication.uploadDataFragment$2.run(uploadDataFragment.java:145) at java.lang.Thread.run(Thread.java:841)