0

I'm trying to upload a video file using mime.MultipartEntityBuilder, but I' getting the following error in my logcat

09-24 14:38:59.673: E/AndroidRuntime(3072): FATAL EXCEPTION: AsyncTask #1
09-24 14:38:59.673: E/AndroidRuntime(3072): java.lang.RuntimeException: An error occured while executing doInBackground()
09-24 14:38:59.673: E/AndroidRuntime(3072):     at android.os.AsyncTask$3.done(AsyncTask.java:299)
09-24 14:38:59.673: E/AndroidRuntime(3072):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
09-24 14:38:59.673: E/AndroidRuntime(3072):     at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
09-24 14:38:59.673: E/AndroidRuntime(3072):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
09-24 14:38:59.673: E/AndroidRuntime(3072):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
09-24 14:38:59.673: E/AndroidRuntime(3072):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
09-24 14:38:59.673: E/AndroidRuntime(3072):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
09-24 14:38:59.673: E/AndroidRuntime(3072):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
09-24 14:38:59.673: E/AndroidRuntime(3072):     at java.lang.Thread.run(Thread.java:856)
09-24 14:38:59.673: E/AndroidRuntime(3072): Caused by: java.lang.NoClassDefFoundError: org.apache.http.entity.ContentType
09-24 14:38:59.673: E/AndroidRuntime(3072):     at org.apache.http.entity.mime.content.FileBody.<init>(FileBody.java:89)
09-24 14:38:59.673: E/AndroidRuntime(3072):     at a.today.a.async.UploadVideoAsync.doInBackground(UploadVideoAsync.java:53)
09-24 14:38:59.673: E/AndroidRuntime(3072):     at a.today.a.async.UploadVideoAsync.doInBackground(UploadVideoAsync.java:1)
09-24 14:38:59.673: E/AndroidRuntime(3072):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
09-24 14:38:59.673: E/AndroidRuntime(3072):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
09-24 14:38:59.673: E/AndroidRuntime(3072):     ... 5 more

This is my codebase:

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.util.EntityUtils;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.content.ContentBody;
import org.apache.http.entity.mime.content.FileBody;

import android.os.AsyncTask;
import android.util.Log;

public class UploadVideoAsync extends AsyncTask<String, String, Object[]> {


    @Override
    protected Object[] doInBackground(String... params) {

        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(params[0].toString());
        final File video = new File(params[1].toString());
        //String video = params[1].toString();
        ContentBody  cb = new FileBody(video);
        try{
            MultipartEntityBuilder entityBuilder  = MultipartEntityBuilder.create();
            entityBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
            //entityBuilder.addPart("video", cb);
            entityBuilder.addBinaryBody("video", video);
            entityBuilder.addTextBody("sid", params[2].toString());
            HttpEntity entity = entityBuilder.build();
            httppost.setEntity(entity);
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity httpEntity = response.getEntity();

            Log.v("result", EntityUtils.toString(httpEntity));

            return new Object[]{response, new BasicResponseHandler().handleResponse(response)};
        }catch (ClientProtocolException e) {

            e.printStackTrace();
       }
        return new Object[0];

    }


}

I am not able to find the exact problem. Can someone tell what is wrong with the code?

1binary0
  • 93
  • 11
  • Problem here An error occured while executing doInBackground() . in doInBackground process – IntelliJ Amiya Sep 24 '15 at 09:24
  • 1
    Yes I know that it is in doInBackground, the problem is occurring at entityBuilder.addBinaryBody("video", video); line, but exactly what is causing it? Logcat says: Caused by: java.lang.NoClassDefFoundError: org.apache.http.entity.ContentType But I have imported ContentType in it. – 1binary0 Sep 24 '15 at 09:26
  • `NoClassDefFoundError` This exception indicates that the JVM looked in its internal class definition data structure for the definition of a class and did not find it – IntelliJ Amiya Sep 24 '15 at 09:28
  • http://stackoverflow.com/questions/26783615/org-apache-http-entity-contenttype-is-not-in-apache-anymore – IntelliJ Amiya Sep 24 '15 at 09:29
  • I have imported import org.apache.http.entity.ContentType; but for some reason it shows unused. – 1binary0 Sep 24 '15 at 09:34

1 Answers1

0

Okay this one solved the problem:

Project -> Properties -> Java Build Path -> Order and Export -> Check the jar files -> OK

This is the screenshot:

Java build path checked jars

1binary0
  • 93
  • 11