0

Hi Im trying to send a file to my server. here is the code :

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

But it crashes at

FileBody bin = new FileBody(file);

The error is:

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)

Hirad Roshandel
  • 2,175
  • 5
  • 40
  • 63

1 Answers1

2

I found the problem. I had to go to hc.apache.org/downloads.cgi and download core,mime,client and cache and include the libraries

Hirad Roshandel
  • 2,175
  • 5
  • 40
  • 63