0

I want to upload an image to server but i need to send 2 more things in order to connect with the server any HELP cause im really stuck on this one.

    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
           // MultipartEntity entity = new MultipartEntity();
            try {



               File file = new File(path);
                // Adding file data to http body
                builder.addPart("image", new FileBody(file));

                // Extra parameters if you want to pass to server
                builder.addTextBody("confid", name);
                builder.addTextBody("udid", id);

                entity = builder.build();
                httppost.setEntity(entity);

                // Making server call
                HttpResponse response = httpclient.execute(httppost);
                HttpEntity r_entity = response.getEntity();

                int statusCode = response.getStatusLine().getStatusCode();
                if (statusCode == 200) {
                    // Server response
                    responseString = EntityUtils.toString(r_entity);
                } else {
                    responseString = "Error occurred! Http Status Code: "
                            + statusCode;
                }

            } catch (ClientProtocolException e) {
                responseString = e.toString();
            } catch (IOException e) {
                responseString = e.toString();
            }

            return responseString;

        }

Here are the errors from android Studio logcat

     0-08 12:06:01.216    8616-8787/? E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #2
java.lang.RuntimeException: An error occured while executing doInBackground()
        at android.os.AsyncTask$3.done(AsyncTask.java:299)
        at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
        at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
        at java.util.concurrent.FutureTask.run(FutureTask.java:137)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
        at java.lang.Thread.run(Thread.java:856)
 Caused by: java.lang.NoClassDefFoundError: org.apache.http.entity.mime.MultipartEntityBuilder
        at com.example.oleg.myapplication.MainActivity$1.uploadFile(MainActivity.java:305)
        at com.example.oleg.myapplication.MainActivity$1.doInBackground(MainActivity.java:285)         at com.example.oleg.myapplication.MainActivity$1.doInBackground(MainActivity.java:279)  at android.os.AsyncTask$2.call(AsyncTask.java:287)
        at  java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
        at java.util.concurrent.FutureTask.run(FutureTask.java:137)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
        at        java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
        at java.lang.Thread.run(Thread.java:856)
moffeltje
  • 4,521
  • 4
  • 33
  • 57
  • You did not tell which problem you have and where. – greenapps Oct 08 '15 at 16:10
  • @greenapps the problem is that even though i added the libraries i got this problem that keeps popping up. Caused by: java.lang.NoClassDefFoundError: org.apache.http.entity.mime.MultipartEntityBuilder. i tryed it in API21 and it works but on 22 i get this error, So i am looking for a solution here :) – OLEG.Alekos Oct 10 '15 at 16:48

0 Answers0