Santhosh S
Santhosh S

Reputation: 99

FATAL EXCEPTION java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/util/Args

I am sending a recorded audio file to the server using the httppost method, but I am receiving the following error:

FATAL EXCEPTION java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/util/Args

Here is my code:

File is = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/" + "javacodegeeksRecording.3gpp");           

String yourNodeJsBluemixRoute = "http://mobilefeedbackform.mybluemix.net";
 try {
     Toast.makeText(MainActivity.this,
            "Inside try", Toast.LENGTH_LONG)
                .show();
        System.out.println(is);
        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost(yourNodeJsBluemixRoute);
        Toast.makeText(MainActivity.this,
                "Before sending", Toast.LENGTH_LONG)
                   .show();
        post.setHeader("enctype", "multipart/form-data");

        /*FileBody bin = new FileBody(is);*/
        FileBody fb = new FileBody(is, "audio/3gpp");
        MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        reqEntity.addPart("file", fb); /*I believe that the "file" is the name in php part*/
        post.setEntity(reqEntity);

        HttpResponse response = client.execute(post);

        Toast.makeText(MainActivity.this,
                "Now sending", Toast.LENGTH_LONG)
                   .show();
        HttpEntity resEntity = response.getEntity();
        if (resEntity != null) {
            String responseBody = EntityUtils.toString(resEntity);
            String resp = responseBody;
            Toast.makeText(MainActivity.this,
                    resp, Toast.LENGTH_LONG)
                       .show();
            Log.i("RESPONSE", EntityUtils.toString(resEntity));
        }
            } catch (Exception e) {
    e.printStackTrace();
        }

       } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
   }

What am I missing?

logcat errors:

08-19 19:57:17.517: E/AndroidRuntime(1377): FATAL EXCEPTION: main
08-19 19:57:17.517: E/AndroidRuntime(1377): Process: com.example.android_test, PID: 1377
08-19 19:57:17.517: E/AndroidRuntime(1377): java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/util/Args;
08-19 19:57:17.517: E/AndroidRuntime(1377):     at org.apache.http.entity.mime.content.AbstractContentBody.<init>(AbstractContentBody.java:48)
08-19 19:57:17.517: E/AndroidRuntime(1377):     at org.apache.http.entity.mime.content.FileBody.<init>(FileBody.java:96)
08-19 19:57:17.517: E/AndroidRuntime(1377):     at org.apache.http.entity.mime.content.FileBody.<init>(FileBody.java:85)
08-19 19:57:17.517: E/AndroidRuntime(1377):     at com.example.android_test.MainActivity.play(MainActivity.java:181)
08-19 19:57:17.517: E/AndroidRuntime(1377):     at com.example.android_test.MainActivity$3.onClick(MainActivity.java:91)
08-19 19:57:17.517: E/AndroidRuntime(1377):     at android.view.View.performClick(View.java:4756)
08-19 19:57:17.517: E/AndroidRuntime(1377):     at android.view.View$PerformClick.run(View.java:19749)
08-19 19:57:17.517: E/AndroidRuntime(1377):     at android.os.Handler.handleCallback(Handler.java:739)
08-19 19:57:17.517: E/AndroidRuntime(1377):     at android.os.Handler.dispatchMessage(Handler.java:95)
08-19 19:57:17.517: E/AndroidRuntime(1377):     at android.os.Looper.loop(Looper.java:135)
08-19 19:57:17.517: E/AndroidRuntime(1377):     at android.app.ActivityThread.main(ActivityThread.java:5221)
08-19 19:57:17.517: E/AndroidRuntime(1377):     at java.lang.reflect.Method.invoke(Native Method)
08-19 19:57:17.517: E/AndroidRuntime(1377):     at java.lang.reflect.Method.invoke(Method.java:372)
08-19 19:57:17.517: E/AndroidRuntime(1377):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
08-19 19:57:17.517: E/AndroidRuntime(1377):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
08-19 19:57:17.517: E/AndroidRuntime(1377): Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.http.util.Args" on path: DexPathList[[zip file "/data/app/com.example.android_test-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
08-19 19:57:17.517: E/AndroidRuntime(1377):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
08-19 19:57:17.517: E/AndroidRuntime(1377):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
08-19 19:57:17.517: E/AndroidRuntime(1377):     at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
08-19 19:57:17.517: E/AndroidRuntime(1377):     ... 15 more
08-19 19:57:17.517: E/AndroidRuntime(1377):     Suppressed: java.lang.ClassNotFoundException: org.apache.http.util.Args
08-19 19:57:17.517: E/AndroidRuntime(1377):         at java.lang.Class.classForName(Native Method)
08-19 19:57:17.517: E/AndroidRuntime(1377):         at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
08-19 19:57:17.517: E/AndroidRuntime(1377):         at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
08-19 19:57:17.517: E/AndroidRuntime(1377):         at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
08-19 19:57:17.517: E/AndroidRuntime(1377):         ... 16 more
08-19 19:57:17.517: E/AndroidRuntime(1377):     Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

Upvotes: 2

Views: 8681

Answers (2)

Atul O Holic
Atul O Holic

Reputation: 6792

Just download the latest http jar from -http://www.java2s.com/Code/Jar/h/Downloadhttpcore43beta1jar.htm]1

and add it into the libs folder of your project.

Don't forget to add compile files('libs/httpcore-4.3-beta1.jar') dependency in the build.gradle

This worked for me. Happy coding :)

Upvotes: 2

Kira
Kira

Reputation: 16

I was also working on apache stuff, and I run into that error. I was able to fix it by downloading the .jar and then link it in the project settings manually.

You should move the jar under your app/build/libs Files >> Project Structure >> Dependencies >> + >> File Dependencies >> and then change it to provided instead of compile (compile will cause a java exit with nonzero value 1 if you are importing too much jars)

Upvotes: 0

Related Questions